[Haskell-cafe] Dynamic types through unsafeCoerce

Taral taralx at gmail.com
Sat Dec 9 18:15:07 EST 2006

On 12/9/06, Alfonso Acosta <alfonso.acosta at gmail.com> wrote:
> Functions like this one are not directy exportable
> myfunc :: (Tyeable a, Typeable b) => MyType a b ...

Well, that's true. Then again, you can't export that type anyway
without use of a StablePtr. All StablePtrs are exportable.

> Uhm thinking about it right now I realized that mgt2mt is hidden to
> the user, so I guess it wouldn't be dangerous if transformations like
> the following one are not.
> MyType Int Char ---> MyGenType ----> MyType a b
> So to summarize, Is transforming a monomorphic type to it's
> polymorphic equivalent through unsafeCoerce a dangerous operation?

Sure it is. The type you gave (MyType Int Char -> MyType a b) can
easily crash your program.

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

More information about the Haskell-Cafe mailing list