[Haskell-cafe] Does somebody know about these functions?

Holger Siegel holgersiegel74 at yahoo.de
Tue Feb 28 21:08:28 CET 2012


Am 28.02.2012 um 20:21 schrieb Johan Holmquist:

>>> 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)
> 
> Except when l == [], but the second equation can be replaced by this nicer one.

Even then. :) (zipWith f l (tail l)) first tries to match l with pattern (a:as), and if that
fails it will not touch its other argument (tail l).




More information about the Haskell-Cafe mailing list