Haskell List of tuples to list?

后端 未结 5 1575
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 13:27

Is it possible to convert a list of tuples [(Int,Int)] as a generic way which valid to any input size ? .. i saw in various questions thats its not possible gen

5条回答
  •  萌比男神i
    2020-12-31 13:52

    You could also use a fold and avoid explicit recursion:

    tupleToList = foldr (\(f,s) a -> f : s : a) []
    

    Or:

    tupleToList = foldl (\a (f,s) -> a ++ [f,s]) []
    

    (For elements of the same type)

提交回复
热议问题