Dynamic types: GHCI works, GHC doesn't?

Alastair Reid reid@cs.utah.edu
02 Jun 2002 15:22:10 +0100

> just as a note, the new version of DrIFT (which i now maintain) has
> the ability to derive 'Typeable',

Very cool.  (Though I'd still like to see Typeable being moved into

> I sort of fudged the Typeable derivation rule, if someone wanted to
> robustify it, i would gladly accept patches.

You should add a few test cases involving functions to your instance -
dashed tricky to get those ones working.  As a challenge, here's a
typical state-passing monad datatype:

   newtype M s a = M (s -> (s,a))

> I dont think that 'unsafe' need be added to Typeable since hopefully
> people will never be creating instances themselves, with the
> instances hidden behind DrIFT and/or 'deriving' clauses then they
> can be assured of being correct (well... as correct as anything is
> :)) .

Sadly, most people aren't using DriFT for that and it seems likely
that people will continue writing them by hand and will continue to
get them wrong.

> Typeable itself is not inherently unsafe, it is broken
> implementations of it which are.

The same situation applies with the use of unsafePerformIO.  There's
nothing wrong with using unsafePerformIO (well, it is semantically a
little ugly but apart from that...) - the problem is people misusing

The idea of putting the word 'unsafe' in the identifiers is:

1) To try to get people to wake up and start thinking hard about what
they're doing when they write these instances (or, if they used DriFT
to generate them, to make them wake up if they start modifying them by

2) To make it easy to home in on problematic pieces of the system when
it starts disobeying Haskell rules.  Typesafety broken?  grep for
'unsafe'.  Referential transparency broken?  grep for 'unsafe'.  
Received puzzling bug report? grep for 'unsafe'.