Oops, it's called toDyn; from Data.Dynamic [1] > toDyn :: Typeable a => a -> Dynamic
-- ryan [1] http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html On Sat, May 30, 2009 at 10:18 PM, <[email protected]> wrote: > Hi Ryan, > > Is there something missing or mislabeled in your post, because I don't see > any definition of toDynamic. > > Michael > > --- On Sun, 5/31/09, Ryan Ingram <[email protected]> wrote: > > From: Ryan Ingram <[email protected]> > Subject: Re: [Haskell-cafe] Missing a "Deriving"? > To: "David Menendez" <[email protected]> > Cc: "michael rice" <[email protected]>, [email protected], "Miguel > Mitrofanov" <[email protected]> > Date: Sunday, May 31, 2009, 12:45 AM > > On Sat, May 30, 2009 at 6:33 PM, David Menendez <[email protected]> wrote: >> *Main> :t searchAll >> searchAll :: (Computation c) => Graph t t1 -> Int -> Int -> c [Int] >> >> The way searchAll is written, the choice of which functions to use >> depends on the type variable c. That's determined by the calling >> context of searchAll, which is why you need to provide a type >> signature when using it at the GHCi command line. > > This is actually one of the most interesting and important things to > "get" about typeclasses; it's not *just* like an interface, because > the instance type can appear in the result of a function and *not* in > the arguments at all. > > In contrast, in Java/C++, the method to use is always chosen by the > object being called; one could argue that all of COM is an attempt to > get around this problem. > > Some examples: > >> fromInteger :: Num a => Integer -> a >> fromDynamic :: Typeable a => Dynamic -> Maybe a > > In both of these cases, the choice of which instance to use is made by > the caller, and often automatically by type inference: > >> test x = case fromDynamic x of >> Just s -> s == "hello" >> Nothing -> False > > Now (test $ toDynamic "hello") = True, but (test $ toDynamic 'a') = > False. Notice that I never directly specified what type "fromDynamic" > should return; but the case statement forces it to return Maybe > String, since I compare (s == "hello") > > -- ryan > > _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
