[Haskell-cafe] Removing alternate items from a list
Yitzchak Gale
gale at sefer.org
Tue Jun 8 08:55:00 EDT 2010
Christopher Done wrote:
> Can't forget fix in a game of code golf!
>
>> (fix $ \f (x:_: xs) -> x : f xs) [1..]
> => [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,4...
Ho, good shot! It only works for infinite lists, though:
Prelude> (fix $ \f (x:_: xs) -> x : f xs) [1..10]
[1,3,5,7,9*** Exception: <interactive>:1:7-30: Non-exhaustive patterns in lambda
Regards,
Yitz
More information about the Haskell-Cafe
mailing list