On Tue, 12 Apr 2005, Hamilton Richards wrote:
Here's a solution:
init :: [a] -> [a]
init xs = tail (foldr keep [] xs)
where
keep :: a -> [a] -> [a]
keep x [] = [x]
keep x [y] = [x,x]
keep x (y:z:zs) = x:x:y:zs
Nice idea!
One case can be eliminated.
init :: [a] -> [a]
init xs = tail (foldr keep [] xs)
where
keep :: a -> [a] -> [a]
keep x [] = [x]
keep x (_:zs) = x:x:zs
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe