Hello list.

I have a problem with Data.Dynamic. The problem is probably that I don't
understand it. From my understanding, the following program should work:

-8<------------------------
import Data.Dynamic

data Foo = Foo { x :: Int }
        deriving Show

instance Typeable Foo where
    typeOf _ = mkAppTy (mkTyCon "Foo.Foo") []


main = do
    let dynObj = toDyn $ Foo 42
    print dynObj
    let Just obj = fromDynamic dynObj :: Maybe Foo
    print obj
-8<------------------------

But when I compile it (ghc Foo.hs) and run it (./a.out) I get:

<<Foo.Foo>>

Fail: Foo.hs:13: Irrefutable pattern failed for pattern (Data.Maybe.Just
obj)

Which indicates that fromDynamic returned Nothing. What is the problem
here? Do I have to employ special trickery to use Dynamic with records?

I'm using ghc 5.04, as packaged by Debian.


Regards,
Martin Sjögren

Attachment: signature.asc
Description: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signeradmeddelandedel

Reply via email to