<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Ross,<br><br>I thought of that, but return, fail, and >>= became "not visible" when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and >>=) and one for MonadPlus (giving it mplus)?<br><br>Michael<br><br>--- On <b>Mon, 6/1/09, Ross Mellgren <i><rmm-haskell@z.odi.ac></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ross Mellgren <rmm-haskell@z.odi.ac><br>Subject: Re: [Haskell-cafe] Missing a "Deriving"?<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: "haskell-cafe Cafe" <haskell-cafe@haskell.org><br>Date: Monday, June 1, 2009, 9:33 PM<br><br><div id="yiv1714632642">mplus is a method of class MonadPlus, so you need to write it in a separate instance
from the one for Monad, e.g.<div><br></div><div>instance MonadPlus Failable where</div><div> mplus = ...</div><div><br></div><div>-Ross</div><div><br></div><div><div><div><div>On Jun 1, 2009, at 9:28 PM, michael rice wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus?<br><br>I'm now getting this error upon loading:<br><br><br>Prelude> :l graph5<br>[1 of 1] Compiling Main ( graph5.hs, interpreted )<br><br>graph5.hs:36:4: `mplus' is not a (visible)
method of class `Monad'<br>Failed, modules loaded: none.<br>Prelude> <br><br><br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><div id="yiv778184410"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">Complete code follows.<br><br>Michael<br><br>=========================<br><br>import Monad<br><br>data Failable a = Success a | Fail String deriving (Show)<br><br>data Graph v e = Graph [(Int,v)] [(Int,Int,e)]<br><br>{-<br>class Computation c where<br> success :: a -> c a<br> failure :: String -> c a<br> augment :: c a -> (a -> c b) -> c b<br> combine :: c a -> c a -> c a<br><br>instance
Computation Maybe where<br> success = Just<br> failure = const Nothing<br> augment (Just x) f = f x<br> augment Nothing _ = Nothing<br> combine Nothing y = y<br> combine x _ = x<br><br>instance Computation Failable where<br> success = Success<br> failure = Fail<br> augment (Success x) f = f x<br> augment (Fail s) _ = Fail s<br> combine (Fail _) y = y<br> combine x _ = x<br>-}<br><br>instance Monad Failable where<br> return = Success<br> fail = Fail<br> (>>=) (Success x) f = f x<br> (>>=) (Fail s) _ = Fail s<br> mplus (Fail _) y = y<br> mplus x _ = x<br><br>{-<br>instance Computation [] where<br> success a
= [a]<br> failure = const []<br> augment l f = concat (map f l)<br> combine = (++)<br><br><br>searchAll g@(Graph vl el) src dst<br> | src == dst = success [src]<br> | otherwise = search' el<br> where search' [] = failure "no path"<br> search' ((u,v,_):es)<br> | src == u = (searchAll g v dst `augment`<br> (success . (u:)))<br> `combine` search'
es<br> | otherwise = search' es<br>-}<br><br>searchAll g@(Graph vl el) src dst<br> | src == dst = return [src]<br> | otherwise = search' el<br> where search' [] = fail "no path"<br> search' ((u,v,_):es)<br> | src == u = (searchAll g v dst >>=<br> (return . (u:)))<br> `mplus` search'
es<br> | otherwise = search' es<br> </td></tr></tbody></table><br> </div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow">Haskell-Cafe@haskell.org</a><br><a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></blockquote></td></tr></tbody></table><br> _______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></div></div></div></blockquote></td></tr></table><br>