[Haskell-cafe] Does somebody know about these functions?
Holger Siegel
holgersiegel74 at yahoo.de
Tue Feb 28 19:45:11 CET 2012
Am 28.02.2012 um 18:06 schrieb Johan Holmquist:
> Two functions that I see useful are described here and I would like to
> know if they are defined in some more or less standard Haskell
> library. Hoogle (http://www.haskell.org/hoogle) did not reveal
> anything about that.
>
>
> Function 'inter' applies given function to each succeeding pair of
> elements of a list.
>
> inter :: (a -> a -> b) -> [a] -> [b]
> inter f [] = []
> inter f l = map (uncurry f) $ zip l (tail l)
This is the same as
inter :: (a -> a -> b) -> [a] -> [b]
inter f l = zipWith f l (tail l)
and you can use it to define the good old Fibonacci sequence:
fibs = 0 : 1 : inter (+) fibs
More information about the Haskell-Cafe
mailing list