[Haskell-cafe] A small puzzle: inTwain as function of foldr

Ketil Malde ketil at malde.org
Fri Jun 5 07:38:24 EDT 2009


Martijn van Steenbergen <martijn at van.steenbergen.nl> writes:

>>> inTwain = foldr (\x (ls, rs) -> if length ls == length rs then (x:ls, rs) else (x:(init ls), (last ls):rs)) ([], [])

> But this uses length and init and last all of which are recursive
> functions. I consider that cheating: only foldr may do the recursion.

inTwain = foldr (\x (ls, rs) -> if foldr (const (+1)) 0 ls = ... ?

:-)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list