How to cast an object to a list of generic type in F#

后端 未结 2 1832
走了就别回头了
走了就别回头了 2020-11-29 09:47

In the following snippet my intention is to convert a System.Object (which could be an FSharpList) to a list of whatever generic type it is holding.

    matc         


        
2条回答
  •  失恋的感觉
    2020-11-29 10:22

    It turns out that either list<'a> or array<'a> can be matched as seq

        match o with
        | :? seq -> addChildCollection(o :?> seq)
        | _           -> addChild(o)
    

    I don't really care that it is a list. As long as I can iterate over it.

提交回复
热议问题