Prelude> (fmap . const ) 2 Just 3
2
Prelude> 2 <$ Just 3
Just 2
Prelude> :t (<$)
(<$) :: Functor f => a -> f b -> f a
Prelude> :t fmap . const
fmap . const :: Functor f => b -> f a -> f b
in functor,
(<$) = fmap . const
why I get different result for Maybe? did not find a implement of <$ in Maybe. Thanks.
(fmap . const) 2 Just 3 is equivalent to ((fmap . const) 2 Just) 3, where 2 <$ Just is const 2 and const 2 3 is 2.
You meant:
(fmap . const) 2 $ Just 3
The problem is that you typed (fmap . const) 2 Just 3. I believe what you meant was rather (fmap . const) 2 (Just 3). In the former, the function fmap . const is applied to three arguments, namely 2, Just and 3, and, in the latter, your expression is indeed equivalent to 2 <$ Just 3.
> (fmap . const) 2 (Just 3)
Just 2
> 2 <$ Just 3
Just 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With