ZVON > References > Haskell reference
| Indexes | Syntax | >> Prelude << | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Prelude
Class: Monad
Instances: [], IO, Maybe
Bibliography: What the hell are Monads?
Monads for the Working Haskell Programmer -- a short tutorial.
Monads





class  Monad m  where
    (>>=)  :: m a -> (a -> m b) -> m b
    (>>)   :: m a -> m b -> m b
    return :: a -> m a
    fail   :: String -> m a

        -- Minimal complete definition:
        --      (>>=), return
    m >> k  =  m >>= \_ -> k
    fail s  = error s

instance Monad Maybe where

    (Just x) >>= k   =  k x
    Nothing  >>= k   =  Nothing
    return           =  Just
    fail s           =  Nothing


instance Monad IO where

   (>>=)  = ...
   return = ...

   m >> k = m >>= \_ -> k
   fail s = error s


instance Monad [] where

    m >>= k          = concat (map k m)
    return x         = [x]
    fail s           = []