
Because you're looking for:
Just 3 >>= return . (+1)
or more simply
Just 3 >>= Just . (+1)
or more generally:
return 3 >>= return . (+1)
The second argument of (>>=) is supposed to be of type (Monad m => a
-> m b) but (+1) ishe of type (Num a => a -> a). Wre is the monad in
that?
Thomas
On Sat, May 9, 2009 at 12:31 PM, michael rice
Why doesn't this work?
Michael
================
data Maybe a = Nothing | Just a
instance Monad Maybe where return = Just fail = Nothing Nothing >>= f = Nothing (Just x) >>= f = f x
instance MonadPlus Maybe where mzero = Nothing Nothing `mplus` x = x x `mplus` _ = x
================
[michael@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude> Just 3 >>= (1+)
<interactive>:1:0: No instance for (Num (Maybe b)) arising from a use of `it' at <interactive>:1:0-14 Possible fix: add an instance declaration for (Num (Maybe b)) In the first argument of `print', namely `it' In a stmt of a 'do' expression: print it Prelude>
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe