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

Geoffrey Marchant geoffrey.marchant at gmail.com
Thu Jun 4 14:21:05 EDT 2009


The linked paper appears to show the right style.
This appears to satisfy the conditions, however:

inTwain as = let (x,y,_) = foldr (\a (r,s,t) -> case (t) of {b:(b':bs) ->
(r,a:s,bs); _ -> (a:r,s,t)}) ([],[],as) as in (x,y)

In the case of a list of odd length, the first half is given the extra
element.


On Thu, Jun 4, 2009 at 8:22 AM, 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?
>
> Is there a general way to tell if a problem can be expressed as a fold?
>
> Thank you,
>
> Martijn.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090604/ced69a63/attachment.html


More information about the Haskell-Cafe mailing list