B/c, - .
: http://homepages.inf.ed.ac.uk/wadler/topics/monads.html#monads - Haskell:
1960 , .
, , "" / "" . ( !) - Maybe:
data Maybe a
= Nothing
| Just a
instance Monad Maybe where
return = Just
Nothing >>= f = Nothing
Just x >>= f = f x
- (Maybe, liftM, return, join), :
liftM :: (a -> b) -> Maybe a -> Maybe b
liftM f mb = mb >>= return . f
join :: Maybe (Maybe a) -> Maybe a
join Nothing = Nothing
join (Just mb) = mb
, liftM Maybe ( !) Maybe, join Maybe ( Just Just:
join (Just (Just x)) = Just x
while Nothing Nothing :
join Nothing = Nothing
join (Just Nothing) = Nothing
). :
Maybe: , .liftM: , , .return: Maybe.join: (, ), , " ".
Maybe - . undef Nothing Just x , x. C/++ t* NULL. Scala : http://www.scala-lang.org/api/current/index.html#scala.Option. "oh, that just exceptions", " ", , , ( Scala foreach). " , " - , Maybe >>=! .
, C Nothing Just Nothing --- . , Haskell, , join , . (, , >>= liftM join, ).
, Haskell IO: GHC IO- GHC -. GHC --- ( !). - . ( ) /!