[Haskell-cafe] Removing alternate items from a list
Sebastiaan Visser
haskell at fvisser.nl
Thu Jun 10 09:37:52 EDT 2010
Or, when lists had a decent eliminator defined in the Prelude (just like maybe for Maybe and either for Either):
list :: b -> (a -> [a] -> b) -> [a] -> b
list d _ [] = d
list _ f (x:xs) = f x xs
fromList = list []
we could write the alternate function like this:
alt :: [a] -> [a]
alt = list [] $ \a -> (a:)
. list [] (const alt)
--
Sebastiaan
On Jun 6, 2010, at 4:46 PM, R J wrote:
> 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
More information about the Haskell-Cafe
mailing list