Are Infinite Types (aka Recursive Types) not possible in F#?

前端 未结 3 1161
南笙
南笙 2020-12-30 06:51

I was chatting with Sadek Drobi on twitter when be brought up that F# didn\'t seem to support Infinite Types. It turns out that in C# you can do something along these lines

3条回答
  •  一生所求
    2020-12-30 07:51

    You can also do something like

    type 'a RecType = RecType of ('a -> 'a RecType)
    

    to create a named type through which to perform the recursion. Now this works:

    let rec specialF = RecType (fun _ -> specialF)
    

提交回复
热议问题