[Haskell-cafe] Indentation Creep

Claus Reinke claus.reinke at talk21.com
Fri Jul 13 19:59:33 EDT 2007

> is there Haskellmagic that I still need to learn?

one bit of magic, coming right up!-) of course, we haskellers are 
the lazy types, and if none of that helps, some Monad often does.

in ghci or hugs, try ':browse Data.Maybe' and ':info Maybe'.

in particular, 'case . of Nothing -> . ; Just . -> .' calls for 'maybe',
and nested chains of such cases call for 'Monad Maybe' and,
possibly, 'MonadPlus Maybe' (the latter from 'Control.Monad').

consider these two (try unfolding the definitions, and compare
with your code):

    maybe (error "nothing") id (lookup False [])

    do { it <- lookup False []; return it }`mplus` return 42

hmm. now, how do i point to the source for that? anyway, here
it is:

    instance  Monad Maybe  where
        (Just x) >>= k   =  k x
        Nothing  >>= k   =  Nothing
        return           =  Just
        fail s           =  Nothing

    instance  MonadPlus Maybe  where
        mzero                 = Nothing
        Nothing `mplus` ys    = ys
        xs      `mplus` ys    = xs


More information about the Haskell-Cafe mailing list