[Haskell-cafe] Removing alternate items from a list

Ozgur Akgun ozgurakgun at gmail.com
Tue Jun 8 11:25:09 EDT 2010


>
> It only works for infinite lists, though
>

you wanted it :)

(fix $ \f xs -> case xs of { (x:_: xs) -> x : f xs; _ -> [] }) [1..10]
= [1,3,5,7,9]

here you go :)

2010/6/8 Yitzchak Gale <gale at sefer.org>

> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100608/2b0bb71f/attachment.html


More information about the Haskell-Cafe mailing list