Fmap fork functions

I want to write functions as follows:

compose :: (a->b->c) -> (d->a) -> (d->b) -> d -> c compose fghx = f (gx) (hx) 

So, we can use it as follows:

 compose (==) (myReverse . myReverse) id [1..100] 

I think this can be simplified with something like "fmap", so it doesn't need to "compile" at all. But I could not figure out how to do this.

+6
source share
1 answer

If you import Control.Applicative , then

 compose fgh = f <$> g <*> h 

So you can write (==) <$> (myReverse . myReverse) <*> id $ [1..100]

<*> , specialized for functions, is equivalent to S-combinator :

 sfgx = fx (gx) 

Perhaps you can also use Control.Arrow :

 compose fgh = g &&& h >>> uncurry f test = uncurry (==) <<< (myReverse <<< myReverse) &&& id $ [1..100] 

Update

I asked lambdabot in #haskell the same question, and it just answered liftM2 .: D

+11
source

Source: https://habr.com/ru/post/895729/


All Articles