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).
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.
A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.
s = (<*>)
for the ((->) r)
Applicative
instance.
Although it doesn't look like it at first, ap
is the S combinator (and join
is the combinator you're really after).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With