F#新手问题。 我有歧视工会等的列表: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 h with
// this is now specific per type
| T1{name=n;id=i} -> loop t ({name=n;id=i}::acc)
| _ -> loop t acc
| [] -> acc
loop l [] |> List.rev
我怎么能做出这样的通用功能在通话 所需的输出类型指定(类型1 |类型2 |类型3)?
您的问题已解决? –