Search code examples
haskellfunctional-programmingfunction-compositionpointfree

Finding haskell higher-order functions


A function which zips a list onto itself can be defined as:

let adjacent1 l = zip l $ tail l

This works, but I'd like to define it in pointfree style. To do this, I define a function dollarize:

let dollarize f1 f2 x = f1 x $ f2 x
let adjacent1 = dollarize zip tail

This works, but obviously I'd rather not define my own higher-order functions. Is there a way to find the standard equivalent of dollarize, assuming it exists? And if not, where are the functions of this sort which exist to combine functions?


Solution

  • The pointfree tool can do this for you automagically.

    $ pointfree "\l -> zip l (tail l)"
    ap zip tail
    $ pointfree "\f1 f2 x -> f1 x $ f2 x"
    ap