[Haskell-cafe] flatten a nested list
pphetra at hotmail.com
Fri Dec 29 02:56:58 EST 2006
I would like to write a program that can do something like this.
;; lisp syntax
* (my-flatten '(1 (2 (3 4) 5)))
(1 2 3 4 5)
I end up like this.
data Store a = E a | S [Store a]
flat :: [Store a] -> [a]
flat  = 
flat ((E x):xs) = [x] ++ flat xs
flat ((S x):xs) = flat x ++ flat xs
*Main> flat [E 1, S[E 2, S[E 3, E 4], E 5]]
Compare to a Lisp solution, It 's not looking good.
View this message in context: http://www.nabble.com/flatten-a-nested-list-tf2893713.html#a8084726
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe