F#新手问题.我有一个受歧视的工会清单,如:
type Type1 = { name:string; id: int; }
type Type2 = { x: float; y: float;}
type Type3 = { x: float; naam:string}
type Union1 =
| T1 of Type1
| T2 of Type2
| T3 of Type3
let lst1 = [ T1 {name="nnn"; id=3}; T2 {x=1.1; y=1.3}; T1 {name="naam1"; id=39}; T3{x=0.0; naam="xx"}];
//To filter out items of Type1, i do:
let fltT1 (l:list<Union1>) :list<Type1> =
let rec loop (l:list<Union1>) (acc:list<Type1>) =
match l with
| h::t -> match …Run Code Online (Sandbox Code Playgroud) 我正在努力理解与CPS的折返.这个我能理解:
let listFoldBack combine acc l =
let rec Loop l cont =
match l with
| h :: t -> Loop t (fun racc -> cont (combine h racc))
| [] -> cont acc
Loop l id
listFoldBack (fun x a -> (2*x::a) ) [] [1;2;3]
// call sequence
[1;2;3] id
Loop [2;3] (fun a -> (combine 1 a))
Loop [3] (fun a -> (combine 1 (combine 2 a)))
Loop [] (fun a -> (combine 1 (combine 2 (combine …Run Code Online (Sandbox Code Playgroud) 有人可以展示如何使用fsharp遍历任意json树的示例.正面树的结构是未知的.必须可以在每个节点确定节点名称,值类型(结构|数组|叶子).在一个结构或数组递归下降.
我试图使用Newtonsoft.Json.Linq,但找不到一些有用的fsharp示例.
我正在尝试这个结构:
type Tree<'a> =
| Leaf
| Node of { value:'a ; left:Tree<'a> ; right:Tree<'a> }
Run Code Online (Sandbox Code Playgroud)
但是f#似乎不支持这个(奇怪的).但接下来如何使用单独的记录类型执行此操作,然后将其置于循环依赖项中.