<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><ryani.spam@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ingram <ryani.spam@gmail.com><br>Subject: Re: [Haskell-cafe] Missing a "Deriving"?<br>To: "David Menendez" <dave@zednenem.com><br>Cc: "michael rice" <nowgate@yahoo.com>, haskell-cafe@haskell.org, "Miguel Mitrofanov" <miguelimo38@yandex.ru><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 <<a rel="nofollow">dave@zednenem.com</a>>
wrote:<br>> *Main> :t searchAll<br>> searchAll :: (Computation c) => Graph t t1 -> Int -> Int -> c [Int]<br>><br>> The way searchAll is written, the choice of which functions to use<br>> depends on the type variable c. That's determined by the calling<br>> context of searchAll, which is why you need to provide a type<br>> 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>> fromInteger :: Num a => Integer -> a<br>> fromDynamic :: Typeable a => Dynamic -> 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>> test x = case fromDynamic x of<br>> Just s -> s == "hello"<br>> Nothing -> False<br><br>Now (test $ toDynamic "hello") = True, but (test $ toDynamic 'a') =<br>False. 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> -- ryan<br></div></blockquote></div></td></tr></table><br>