Problem with Data.Dynamic

Martin Sjögren md9ms@mdstud.chalmers.se
25 Oct 2002 01:27:37 +0200


--=-9zTs6AKJlD9rUouoXzkI
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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 =3D Foo { x :: Int }
        deriving Show

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


main =3D do
    let dynObj =3D toDyn $ Foo 42
    print dynObj
    let Just obj =3D 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=F6gren

--=-9zTs6AKJlD9rUouoXzkI
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signerad
	meddelandedel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQA9uIHpGpBPiZwE9FYRApNpAJwNYcyptlyr+tz4e4JoBB9MS+tEBgCbBHKb
i9k8rBx6ZIzRjV719U29EGA=
=ezxO
-----END PGP SIGNATURE-----

--=-9zTs6AKJlD9rUouoXzkI--