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

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Jun 4 10:33:36 EDT 2009


On Thu, Jun 4, 2009 at 4:22 PM, Martijn van Steenbergen
<martijn at van.steenbergen.nl> wrote:
> Bonjour café,
>
> A small puzzle:
>
> Consider the function inTwain that splits a list of even length evenly into
> two sublists:
>
>> inTwain "Hello world!"
> ("Hello ","world!")
>
> Is it possible to implement inTwain such that the recursion is done by one
> of the standard list folds?

I don't think it is without a length before at least. On the other
hand if your specification is just "splits a list of even length
evenly into two sublists", you can contrive something with a simple
foldr :

inTwain = foldr (\x ~(xs,ys) -> (ys, x:xs)) ([],[])

-- 
Jedaï


More information about the Haskell-Cafe mailing list