Here are two combinators that I have actually used in my code (the first one is fairly common):
dot :: (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
dot = ((.).(.))
swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing = flip . (. flip id)
Imagine (or better: provide!) Scheme versions or their idiomatic equivalents.
Of course the point-free definitions makes them a bit hard to understand, but I wanted to demonstrate terseness. `dot' also has a nice point-full definition:
dot f g a b = f (g a b)
The use case for `dot' should be obvious from the latter definition. I leave the point-full definition (and a use case) for `swing' as an exercise. Let me just note that Lisp would carry some more syntactic baggage for the definition and use of both of these combinators.
However, you can't beat Lisp, when it comes to Quines:
((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))
Haskell's facilities for talking about Haskell code are more verbose.
P.S. for completeness sake, to make the exercise above easier without doing a search:
Compare:
I hope both versions are fairly idiomatic.Here are two combinators that I have actually used in my code (the first one is fairly common):
Imagine (or better: provide!) Scheme versions or their idiomatic equivalents.Of course the point-free definitions makes them a bit hard to understand, but I wanted to demonstrate terseness. `dot' also has a nice point-full definition:
The use case for `dot' should be obvious from the latter definition. I leave the point-full definition (and a use case) for `swing' as an exercise. Let me just note that Lisp would carry some more syntactic baggage for the definition and use of both of these combinators.However, you can't beat Lisp, when it comes to Quines:
Haskell's facilities for talking about Haskell code are more verbose.P.S. for completeness sake, to make the exercise above easier without doing a search: