
28 Feb
2012
28 Feb
'12
6:45 p.m.
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