I'm learning about applicative functors. In the source for an applicative Maybe
, the pure
function looks like this:
instance Applicative Maybe where
pure = Just
...etc
With the arguments expanded, I think it looks like:
pure x = Just x
When I call pure (Just 5)
, it returns Just 5
.
Shouldn't it return Just (Just 5)
?
Similarly, for List:
instance Applicative [] where
pure x = [x]
When I call pure [4,5,6]
it returns [4,5,6]
.
From the signature, it looks like pure [4,5,6]
should return [[4,5,6]]
.
Can someone explain in simple terms what's happening here?
Wait, I think I got it - since there's no context provided, pure [4,5,6]
is not using the Applicative
for List
, it's just using the general case and returning the same value. Is this correct?