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
hth,
claus
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe