This is an old revision of the document!


Maybe

Haskell type

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

Discussion

Reference

hackage: Source

Parents

Element of

Link to graph
Log In
Improvements of the human condition