[Haskell-cafe] Foldr tutorial, Inspired by Getting a Fix from a Fold

Lennart Augustsson lennart at augustsson.net
Mon Feb 12 14:40:31 EST 2007


Sure, but we also have

para f e xs = snd $ foldr (\ x ~(xs, y) -> (x:xs, f x xs y)) ([], e) xs

So I think using para is fine.

	-- Lennart

On Feb 12, 2007, at 18:40 , Bernie Pope wrote:

> Nicolas Frisby wrote:
>> Guess this is a tricky choice for a foldr intro, since it requires a
>> "paramorphism" (see bananas lenses wires etc.)
>>
>> para :: (a -> [a] -> b -> b) -> b -> [a] -> b
>> para f e [] = e
>> para f e (x:xs) = f x xs (para f e xs)
>>
>> -- note that the original tail of the list (i.e. xs and not xs') is
>> used in the else-branch
>> dropWhile' p = para (\x xs xs' -> if p x then xs' else (x:xs)) []
> Actually, several people tried to use para, but of course it is not  
> in the spirit of the challenge :)
>
> Cheers,
> Bernie.
> _______________________________________________
> 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