Pregunta

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).

¿Fue útil?

Solución

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

Otros consejos

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

It can also be used (=<<), (>>=).

And they are included in Prelude

instance Monad ((->) r) where  
    return = const
    f >>= k = \ r -> k (f r) r  
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top