我一直在爲一些F#模塊添加一些方便的方法,例如List。擴展F#列表模塊
type Microsoft.FSharp.Collections.FSharpList<'a> with //'
static member iterWhile (f:'a -> bool) (ls:'a list) =
let rec iterLoop f ls =
match ls with
| head :: tail -> if f head then iterLoop f tail
| _ ->()
iterLoop f ls
我想知道是否可以添加突變?我知道列表是不可變的,所以如何添加一個可變的方法給Ref類型List。像這樣的東西。
type Ref<'a when 'a :> Microsoft.FSharp.Collections.FSharpList<'a> > with //'
member this.AppendMutate element =
this := element :: !this
還是有某種方法來約束泛型只接受可變嗎?