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).
\f x -> f x x
isjoin
in the function monad. – Myer(.)
,($)
, possiblyflip
:). – Sinaloa\f x -> f x x
is not the S combinator. The S combinator is\f g x -> f x (g x)
, which is a free theorem for its type. – Tresatrescha\f g x -> f x (g x)
is an existence proof that the type(a -> b -> c) -> (a -> b) -> a -> c
is inhabited. This function can be generated mechanically, i.e. "for free", in a way that is explained here: https://mcmap.net/q/190386/-how-does-djinn-work. And, in fact, if you wanted to find a function(<*>)
to use for for((->) r
, you could just ask Djinn to do the proof for you. – Tresatrescha