, , <$> infix fmap. , , :
GHCi> (*2) <$> (Just 3)
Just 6
GHCi> (*2) <$> (Nothing)
Nothing
GHCi> (*3) <$> (Right 7)
Right 21
GHCi> (*2) <$> (Left "error")
Left "error"
GHCi> (+ 1) <$> [2,4,6,8]
[3,5,7,9]
:
GHCi> (*) <$> (Just 2) <*> (Just 5)
Just 10
GHCi> (*) <$> (Just 2) <*> (Nothing)
Nothing
GHCi> (*) <$> (Right 3) <*> (Right 7)
Right 21
GHCi> (*) <$> (Left "error") <*> (Right 7)
Left "error"
GHCi> (+) <$> [1,2,3] <*> [10,20,30]
[11,21,31,12,22,32,13,23,33]
GHCi> (+) <$> [1,2,3] <*> []
[]
:
GHCi> (Just (*2)) <*> (Just 5)
Just 10
GHCi> (Right (*3)) <*> (Right 7)
Right 21
GHCi> [(+1),(+2),(+3)] <*> [10,20,30]
[11,21,31,12,22,32,13,23,33]
, , , , , (*) <$> (Just 2) <*> (Just 5) Just (2 * 5)
( , , .)
, <$> " " , , , (, Nothng, ).
<*> . , , . , (*) <$> (Right 3) <*> (Right 7) <*> (Right 4) - - * 3 7, , , 4.
, <$> <*> , . .
This can only be done if the box itself is a functor; this is a key limitation for all of this. A functor is a function for which someone has defined a function fmapthat allows you to convert it from a function applied to one type to a function applicable to another type (without changing the essential nature of the function). If you like, Monads (boxes for things) know how to transform functions so that they can be applied to their things.