<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div id="yiv1427792333">Hi Ryan,<br><br>Is there something missing or mislabeled in your post, because I don't see any definition of toDynamic.<br><br>Michael<br><br>--- On <b>Sun, 5/31/09, Ryan Ingram <i>&lt;ryani.spam@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ingram &lt;ryani.spam@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] Missing a "Deriving"?<br>To: "David Menendez" &lt;dave@zednenem.com&gt;<br>Cc: "michael rice" &lt;nowgate@yahoo.com&gt;, haskell-cafe@haskell.org, "Miguel Mitrofanov" &lt;miguelimo38@yandex.ru&gt;<br>Date: Sunday, May 31, 2009, 12:45 AM<br><br><div class="plainMail">On Sat, May 30, 2009 at 6:33 PM, David Menendez &lt;<a rel="nofollow">dave@zednenem.com</a>&gt;
 wrote:<br>&gt; *Main&gt; :t searchAll<br>&gt; searchAll :: (Computation c) =&gt; Graph t t1 -&gt; Int -&gt; Int -&gt; c [Int]<br>&gt;<br>&gt; The way searchAll is written, the choice of which functions to use<br>&gt; depends on the type variable c. That's determined by the calling<br>&gt; context of searchAll, which is why you need to provide a type<br>&gt; signature when using it at the GHCi command line.<br><br>This is actually one of the most interesting and important things to<br>"get" about typeclasses; it's not *just* like an interface, because<br>the instance type can appear in the result of a function and *not* in<br>the arguments at all.<br><br>In contrast, in Java/C++, the method to use is always chosen by the<br>object being called; one could argue that all of COM is an attempt to<br>get around this problem.<br><br>Some examples:<br><br>&gt; fromInteger :: Num a =&gt; Integer -&gt; a<br>&gt; fromDynamic :: Typeable a =&gt; Dynamic -&gt; Maybe
 a<br><br>In both of these cases, the choice of which instance to use is made by<br>the caller, and often automatically by type inference:<br><br>&gt; test x = case fromDynamic x of<br>&gt;&nbsp; &nbsp; Just s -&gt; s == "hello"<br>&gt;&nbsp; &nbsp; Nothing -&gt; False<br><br>Now (test $ toDynamic "hello") = True, but (test $ toDynamic 'a') =<br>False.&nbsp; Notice that I never directly specified what type "fromDynamic"<br>should return; but the case statement forces it to return Maybe<br>String, since I compare (s == "hello")<br><br>&nbsp; -- ryan<br></div></blockquote></div></td></tr></table><br>