Summing over lists of arbitrary levels of nestedness in F#
问题 I'm trying to create an F# function that will return the sum of a list of int s of arbitrary nestedness. Ie. it will work for a list<int> , a list<list<int>> and a list<list<list<list<list<list<int>>>>>> . In Haskell I would write something like: class HasSum a where getSum :: a -> Integer instance HasSum Integer where getSum = id instance HasSum a => HasSum [a] where getSum = sum . map getSum which would let me do: list :: a -> [a] list = replicate 6 nestedList :: [[[[[[[[[[Integer]]]]]]]]]]