[Haskell-cafe] Re: Something like scan1
Henning Thielemann
lemming at henning-thielemann.de
Wed Jun 18 11:06:13 EDT 2008
On Wed, 18 Jun 2008, Achim Schneider wrote:
> Henning Thielemann <lemming at henning-thielemann.de> wrote:
>
>> On Wed, 18 Jun 2008, Achim Schneider wrote:
>>
>>> Is there a generalisation of scan1, such that eg.
>>>
>>> foo (+) [0,1] (1,2) = [0,1,1,2,3,5,8,13,...]
>>>
>>> ?
>>
>> What is the (1,2) for?
>>
> Specifying the relative indexes an element depends on. Ideally, it
> should be generalised for n-ary functions.
foo f prefix (n,m) =
let k = length prefix
xs = prefix ++ zipWith f (xss!!(k-n)) (xss!!(k-m))
xss = List.tails xs
in xs
More information about the Haskell-Cafe
mailing list