I am playing with Control.Applicative
and I am realizing I don't understand everything with the Haskell type system.
Here is my experiment in 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 of <*>
is f (a -> b)
.
- Why is this expression correct?
- How can it be unified with
(pure 2)
since the constant2
is not of typea -> b
? - What does
Num (a -> b)
mean? How can a function having aa -> b
type be an instance ofNum
?
Num (a -> b)
in the context doesn't mean there is aNum
instance fora -> b
. It means "if there were" aNum
instance fora -> b
then the expression would have this type. – Tom Ellis2 :: Num a => a
. – Zeta:t (<*>) (pure (2 :: Int))
– viorior