[Haskell-cafe] Is using Data.Dynamic considered a no-go?

Jonathan Cast jonathanccast at fastmail.fm
Thu Feb 12 13:24:21 EST 2009

On Thu, 2009-02-12 at 19:04 +0100, Lennart Augustsson wrote:
> They are not unsafe in the way unsafePerformIO is,

I beg permission to demur:

  newtype Unsafe alpha = Unsafe { unUnsafe :: alpha }
  instance Typeable (Unsafe alpha) where
    typeOf _ = typeOf ()

  pseudoSafeCoerce :: alpha -> Maybe beta
  pseudoSafeCoerce = fmap unUnsafe . cast . Unsafe

Note that

  pseudoSafeCoerce = Just . unsafeCoerce

> but I regard them
> as a last resort in certain situations.
> Still, in those situations they are very useful.

But I would agree with both of these.  As long as you *derive* Typeable.


More information about the Haskell-Cafe mailing list