我需要帮助理解以下陈述:
let dictionary = [ for i in 1..4 -> i, true ] |> Map.ofSeq
Run Code Online (Sandbox Code Playgroud)
具体来说,我对有关使用括号的规则感到困惑。
笔记
我对 F# 一无所知。所以请原谅我的无知。
这些是 F# 中使用的括号
()
(1, 2) // Tuple (separator is a comma)
() // empty tuple, called unit
Run Code Online (Sandbox Code Playgroud)
[]
[ 1; 2 ] // List
[] // List.empty
[| 1; 2 |] // Array
[||] // Array.empty
Run Code Online (Sandbox Code Playgroud)
{}
seq { yield 1; yield 2 } // Sequence
Seq.empty // empty Sequence, not {}
async { return 1 } // Computation Expressions, e.g. async
type record = // Record type definition
{ Name : string
Age : int
}
Run Code Online (Sandbox Code Playgroud)
<>
type A<'T> = A of 'T
Run Code Online (Sandbox Code Playgroud)
类型可以轻松组合
let composition =
async { return
[|
[ ("A",1); ("B",2) ]
[ ("C",3) ]
|]
}
// val composition : Async<(string * int) list []>
Run Code Online (Sandbox Code Playgroud)