[Haskell-cafe] Removing alternate items from a list

Ozgur Akgun ozgurakgun at gmail.com
Tue Jun 8 10:17:56 EDT 2010


if we add 'a' to the definition of this function, (to make it work), the
type of it turns out to be: [a] -> [(a, Bool)]

you might have forgotten the "map fst $" part.

Best,

On 8 June 2010 14:51, Bill Atkins <watkins at alum.rpi.edu> wrote:

> f :: [a] -> [a]
> f = filter snd $ zip a (cycle [True, False])
>
> On Monday, June 7, 2010, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> > or, since you don't need to give a name to the second element of the
> list:
> >
> > f :: [a] -> [a]
> > f (x:_:xs) = x : f xsf x = x
> >
> >
> >
> >
> > On 7 June 2010 20:11, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> >
> > i think explicit recursion is quite clean?
> >
> >
> > f :: [a] -> [a]f (x:y:zs) = x : f zs
> >
> > f x = x
> >
> >
> > On 7 June 2010 19:42, Thomas Hartman <tphyahoo at gmail.com> wrote:
> > maybe this?
> >
> > map snd . filter (odd . fst) . zip [1,2..] $ [1,2,3,4,5]
> >
> > 2010/6/6 R J <rj248842 at hotmail.com>:
> >> What's the cleanest definition for a function f :: [a] -> [a] that takes
> a
> >> list and returns the same list, with alternate items removed?  e.g., f
> [0,
> >> 1, 2, 3, 4, 5] = [1,3,5]?
> >>
> >> ________________________________
> >> The New Busy is not the old busy. Search, chat and e-mail from your
> inbox.
> >> Get started.
> >> _______________________________________________
> >> Haskell-Cafe mailing list
> >> Haskell-Cafe at haskell.org
> >> http://www.haskell.org/mailman/listinfo/haskell-cafe
> >>
> >>
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
> > --
> > Ozgur Akgun
> >
> >
> > --
> > Ozgur Akgun
> >
>



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


More information about the Haskell-Cafe mailing list