Jump to content

Flatten a list: Difference between revisions

Line 1,710:
= Leaf a
| Node [Tree a]
 
flatten :: Tree a -> [a]
flatten (Leaf x) = [x]
flatten (Node xs) = concatMapxs flatten>>= xsflatten
 
main :: IO ()
main =
Line 1,728:
, Node []
]
-- output: [1,2,3,4,5,6,7,8]</lang>
 
Yet another choice, custom data structure, efficient lazy flattening:
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.