Understanding a Haskell Type System in the Application Context

I play with Control.Applicative, and I understand that I don’t understand everything with a system like Haskell.

Here is my experiment at Ghci:

λ :t (<*>)
(<*>) :: Applicative f => f (a -> b) -> f a -> f b

λ :t (<*>) (pure 2)
(<*>) (pure 2) :: (Num (a -> b), Applicative f) => f a -> f b

The type of the first argument <*>is f (a -> b).

  • Why is this expression correct?
  • How can this be combined with (pure 2), since a constant is 2not a type a -> b?
  • What does it mean Num (a -> b)? How is a function having a type a -> ban instance Num?
+4
source share
1 answer

<*> f (a -> b). (<*>) (pure x) , x - - .

2 - Num a => a. , 2 , Num.

, (<*>) (pure 2) , 2 , Num.

, , - Num. . , , .

( , , , - Integral Fractional . . ...)

+7

All Articles