3 ms·
> (+) <$> (Just 5) Just (+5) > Just (+5) <$> (Just 4) ERROR ??? WHAT DOES THIS EVEN MEAN WHY IS THE FUNCTION WRAPPED IN A JUST A functor takes a
by GhotiFish 13y ago
> (+) <$> (Just 5)
Just (+5)
> Just (+5) <$> (Just 4)
ERROR ??? WHAT DOES THIS EVEN MEAN WHY IS THE FUNCTION
WRAPPED IN A JUST
A functor takes a function, and applies it to the inside of a context, but all of a sudden now a functor can't take a function and apply it to the inside of a context.
No, that will never make sense. Sorry. Haskell is hard.
edit: oh, it's in a just value, I didn't notice that the first time I read it, for... some reason.
- deleted 13y ago[deleted]
- usea 13y agoI stumbled on the exact same thing. Eventually I just moved on without knowing what I was missing. Your post pointed it out to me, thanks.
- antninja 13y ago"Just (+5)" is not a function. This would have worked with: (+5) <$> (Just 4)
- tel 13y agoOr Just (+5) <*> Just 4 as it turns out.
- chongli 13y ago>A functor takes a function, and applies it to the inside of a context, but all of a sudden now a functor can't take a function and apply it to the inside of a context. Where you're getting mixed up is in the distinction between Functors and Applicative Functors. You can think of an Applicative Functor as one which allows you to apply its contents to other things. One function which must be defined for all Applicative Functors is: (<*>) :: f (a -> b) -> f a -> f b Looking at the type signature, this is a function of two arguments. The first argument is an Applicative Functor containing a function. The second argument is the same functor containing a value to which that function may be applied. What does this function do? It simply applies the function and returns the result, wrapped in the same Functor. Thus: Just (+5) <*> Just 4 >>> Just 9 This is very much analogous to typical function application: (+5) 4 >>> 9 Which is why the function (<*>) is usually pronounced "ap" or "applied over".