Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 827
Marcin Avatar asked Oct 24 '12 21:10

Marcin


1 Answers

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
like image 170
hammar Avatar answered Sep 21 '22 16:09

hammar