Explicit definition of which pure function to use

One example from Learn You the Haskell :

pure (+) <*> Just 3 <*> Just 5

He claims:

So first pure (+), whatJust (+)

I assume that Haskell uses type inference in a function <*>to determine that the function pureon the LHS will be the one from the instance Maybeof the type class Applicative(based on the fact that we use Just 5RHS, a Just- Maybe).

However, is there ever a case when you want to use the Applicative Functor using a method pure, but you are not going to use it directly through a function <*>and therefore Haskell cannot determine which function to pureuse? If so, how would you be the explicit state in which the function is pureused ?

Or maybe Haskell will not try to determine which function pureuntil the result of the function pureis used in some context (for example, when you pass it to a function <*>at some point)

+5
source share
1 answer

. , :

foo :: Maybe (Integer -> Integer -> Integer)
foo = pure (+)

( let where.)

, , (pure (+) :: Maybe (Integer -> Integer -> Integer)).

pure, . :

pure :: (Applicative f) => a -> f a

... (pure :: a -> Maybe a), a pure . (pure :: a -> Maybe a) (+) , pure (+) :: Maybe (Integer -> Integer -> Integer), , , .

, : pure (+) (, Maybe (Integer -> Integer -> Integer)) - . ( : - , , , - ... , , .)

+11

All Articles