I want to compose functions in the following way:
compose :: (a->b->c) -> (d->a) -> (d->b) -> d -> c
compose f g h x = f (g x) (h x)
So that we can use it in the following way:
compose (==) (myReverse . myReverse) id [1..100]
I think it could be simplified with something like 'fmap', so that it needn't define 'compose' at all. But I failed to figure out how to do that.
If you import Control.Applicative
, then
compose f g h = f <$> g <*> h
So, you can write (==) <$> (myReverse . myReverse) <*> id $ [1..100]
<*>
specialized to functions is equivalent to the S-combinator:
s f g x = f x (g x)
You can probably use Control.Arrow
too:
compose f g h = g &&& h >>> uncurry f
test = uncurry (==) <<< (myReverse <<< myReverse) &&& id $ [1..100]
Update
I've asked lambdabot
at #haskell
the same question and he answered simply liftM2
. :D
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