将可折叠结构展平为列表
toList
将 Foldable
结构 t a
展平为 a
s 列表。
ghci> toList [7, 2, 9] -- t ~ []
[7, 2, 9]
ghci> toList (Right 'a') -- t ~ Either e
"a"
ghci> toList (Left "foo") -- t ~ Either String
[]
ghci> toList (3, True) -- t ~ (,) Int
[True]
toList
被定义为等同于:
class Foldable t where
-- ...
toList::t a -> [a]
toList = foldr (:) []