[Haskell-cafe] Missing a "Deriving"?

Ryan Ingram ryani.spam at gmail.com
Sun May 31 01:45:59 EDT 2009


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,  <nowgate at yahoo.com> 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 <ryani.spam at gmail.com> wrote:
>
> From: Ryan Ingram <ryani.spam at gmail.com>
> Subject: Re: [Haskell-cafe] Missing a "Deriving"?
> To: "David Menendez" <dave at zednenem.com>
> Cc: "michael rice" <nowgate at yahoo.com>, haskell-cafe at haskell.org, "Miguel
> Mitrofanov" <miguelimo38 at yandex.ru>
> Date: Sunday, May 31, 2009, 12:45 AM
>
> On Sat, May 30, 2009 at 6:33 PM, David Menendez <dave at zednenem.com> 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
>
>


More information about the Haskell-Cafe mailing list