[Haskell-cafe] Dynamic types through unsafeCoerce

Taral taralx at gmail.com
Sat Dec 9 13:47:17 EST 2006

On 12/9/06, Alfonso Acosta <alfonso.acosta at gmail.com> wrote:
> I've been using Data.Dynamic but the Typeable requirement doesn't go
> well with FFI declarations (which don't accept type contexts).

Can you be a little more specific?

> mt2mgt :: MyType a b -> MyGenType
> mt2mgt = MyGenType.myToDyn
> mgt2mt :: MyGentype -> MyType a b
> mgt2mt (MyGenType dyn) = myfromDyn dyn
> The question is, ¿if only mt2mgt and mgt2mt are used by the user,
> would the use of unsafeCoerce be dangerous?

mgt2mt . mt2mgt :: MyType a b -> MyType c d

Yes, it's dangerous. The reason Dynamic requires Typeable is to be
able to check that you're casting Dynamic back to the original type.

Taral <taralx at gmail.com>
"You can't prove anything."
    -- Gödel's Incompetence Theorem

More information about the Haskell-Cafe mailing list