Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S combinator in Haskell

Can an analog of the S combinator be expressed in Haskell using only standard functions (without defining it by equation) and without using lambda (anonymous function)? I expect it to by of type (a -> b -> c) -> (a -> b) -> a -> c.

For example, an analog of the K combinator is just const.

In fact i am trying to express the function \f x -> f x x using standard functions, but cannot think of any standard non-linear function to start with (that is a function that uses its argument more than once).

like image 731
Alexey Avatar asked Apr 15 '14 21:04

Alexey


People also ask

What is Combinator in Haskell?

Haskell. Copy. But informally… a combinator is something that combines other things. And it is in that informal sense that we use it here! In our context, parser combinators are functions on parsers: functions that combine and transform parsers into other parsers, to handle such things as backtracking, or repetition.

What is a Combinator in programming?

A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.


2 Answers

s = (<*>) for the ((->) r) Applicative instance.

like image 175
David Young Avatar answered Sep 30 '22 05:09

David Young


Although it doesn't look like it at first, ap is the S combinator (and join is the combinator you're really after).

like image 37
Daniel Wagner Avatar answered Sep 30 '22 06:09

Daniel Wagner