  wren ng thornton wren at freegeek.org Wed Mar 25 15:19:02 EDT
2009  Thomas Hartman wrote: > sorry, wrong function. > should be
> partitions [] xs = [] > partitions (n:parts) xs = >   let
(beg,end) = splitAt n xs >   in beg : ( case end of >
[] -> [] >                xs -> partitions parts xs)  It's not
tail recursive, FWIW. The recursive expression has (:) as it's
head before it hits `partitions`. It is however nicely
coinductive,  which has other good properties.  We could make it
tail-recursive easily,     partitions = go id        go k []
xs = k []        go k (n:ns) xs =            let (beg,end) =
splitAt n xs                k'        = k . (beg:)            in
case end of                []  -> k' []                xs' -> go
k' ns xs'  (Note how this version has `go` as the head of the
recursive expression.)  ...however this version has different
strictness properties. In  particular, let both input lists be
infinite (and take a finite portion  of the result). The
original version w