Maybe

Haskell type

data  Maybe a  =  Nothing | Just a
  deriving (Eq, Ord)
 
instance  Monad Maybe  where
    (Just x) >>= k      = k x
    Nothing  >>= _      = Nothing
 
    return              = Just
    fail _              = Nothing
 
-- utility
 
   (Just _) >>  k      = k
   Nothing  >>  _      = Nothing
 
  instance  Functor Maybe  where
    fmap _ Nothing       = Nothing
    fmap f (Just a)      = Just (f a)

Discussion

Reference

hackage: Source

Parents

Element of

Monad . Haskell