<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Miguel,<br><br>That works. but it gives just a single solution [1,2,3] when there are supposed to be two [[1,2,3],[1,4,3]]. Of course the code in YAHT may be in error.<br><br>Also, how the heck does Haskell decide which "success", "failure", "augment", and "combine" to use in function "searchAll", since there are five possibilities.<br><br>MIchael<br><br>--- On <b>Sat, 5/30/09, Miguel Mitrofanov <i>&lt;miguelimo38@yandex.ru&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Miguel Mitrofanov &lt;miguelimo38@yandex.ru&gt;<br>Subject: Re: [Haskell-cafe] Missing a "Deriving"?<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: haskell-cafe@haskell.org<br>Date: Saturday, May 30, 2009, 5:36 PM<br><br><div class="plainMail">It's trying to 'Show' the 'c [Int]' type, but doesn't know
 which 'c' to use; so it's trying to find a generic instance, which doesn't exist. You can't fix this with 'deriving' or anything like this; instead, provide the type annotation like this:<br><br>*Main&gt; searchAll g 1 3 :: Maybe [Int]<br><br>On 31 May 2009, at 00:50, michael rice wrote:<br><br>&gt; The following code is from Section 8.4.2, pgs. 111-112 (PDF paging) of YAHT.<br>&gt; <br>&gt; It compiles fine, but upon trying it I get the following error message.<br>&gt; <br>&gt; It seems to be trying to 'Show' the Computation class but I'm not sure where to put the 'Deriving'.<br>&gt; <br>&gt; Michael<br>&gt; <br>&gt; <br>&gt; ============<br>&gt; <br>&gt; Loading package ghc-prim ... linking ... done.<br>&gt; Loading package integer ... linking ... done.<br>&gt; Loading package base ... linking ... done.<br>&gt; [1 of 1] Compiling Main&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;( graph4.hs, interpreted )<br>&gt; Ok, modules loaded:
 Main.<br>&gt; *Main&gt; let g = Graph [(1,'a'),(2,'b'),(3,'c'),(4,'d')] [(1,2,'p'),(2,3,'q'),(1,4,'r'),(4,3,'s')]<br>&gt; *Main&gt; searchAll g 1 3<br>&gt; <br>&gt; &lt;interactive&gt;:1:0:<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;No instance for (Show (c [Int]))<br>&gt;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;arising from a use of `print' at &lt;interactive&gt;:1:0-14<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;Possible fix: add an instance declaration for (Show (c [Int]))<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;In a stmt of a 'do' expression: print it<br>&gt; <br>&gt; ============================<br>&gt; <br>&gt; data Failable a = Success a | Fail String deriving (Show)<br>&gt; <br>&gt; data Graph v e = Graph [(Int,v)] [(Int,Int,e)]<br>&gt; <br>&gt; class Computation c where<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;success :: a -&gt; c a<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;failure :: String -&gt; c a<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;augment :: c a -&gt; (a -&gt; c b) -&gt; c b<br>&gt;&nbsp;
 &nbsp;&nbsp;&nbsp;combine :: c a -&gt; c a -&gt; c a<br>&gt; <br>&gt; instance Computation Maybe where<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;success = Just<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;failure = const Nothing<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;augment (Just x) f = f x<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;augment Nothing _ = Nothing<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;combine Nothing y = y<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;combine x _ = x<br>&gt; <br>&gt; instance Computation Failable where<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;success = Success<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;failure = Fail<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;augment (Success x) f = f x<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;augment (Fail s) _ = Fail s<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;combine (Fail _) y = y<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;combine x _ = x<br>&gt; <br>&gt; instance Computation [] where<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;success a = [a]<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;failure = const []<br>&gt;&nbsp;
 &nbsp;&nbsp;&nbsp;augment l f = concat (map f l)<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;combine = (++)<br>&gt; <br>&gt; searchAll g@(Graph vl el) src dst<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;| src == dst = success [src]<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;| otherwise = search' el<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;where search' [] = failure "no path"<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;search' ((u,v,_):es)<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;| src == u = (searchAll g v dst `augment`<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (success . (u:)))<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;`combine` search' es<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;| otherwise = search' es<br>&gt; <br>&gt; <br>&gt; _______________________________________________<br>&gt;
 Haskell-Cafe mailing list<br>&gt; <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br><br></div></blockquote></td></tr></table><br>