John Meacham | 2 Jun 2002 10:51
Favicon

Re: Dynamic types: GHCI works, GHC doesn't?

just as a note, the new version of DrIFT (which i now maintain)
has the ability to derive 'Typeable', which is used for the Strafunski
generic programming representation (which it also can derive..)
the homepage is now at 'http://repetae.net/john/computer/haskell/DrIFT'
I sort of fudged the Typeable derivation rule, if someone wanted to
robustify it, i would gladly accept patches.

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 :)) . Typeable
itself is not inherently unsafe, it is broken implementations of it
which are. 
	John

On Sun, Jun 02, 2002 at 12:11:49PM +1000, Andre Pang wrote:
> On Sat, Jun 01, 2002 at 07:56:39PM +0100, Alastair Reid wrote:
> 
> > Your Typeable instance looks like this:
> > 
> > > instance Typeable FootnoteData where
> > >    typeOf _ = mkAppTy (mkTyCon "FootnoteData") [typeOf ("Foo" :: String), typeOf (7 :: Int)]
> > 
> > This should be written:
> > 
> > > instance Typeable FootnoteData where
> > >    typeOf _ = mkAppTy fdtc [typeOf ("Foo" :: String), typeOf (7 :: Int)]
> > >
> > > fdtc = mkTyCon "FootnoteData"
> > 
(Continue reading)

Alastair Reid | 2 Jun 2002 16:22
Picon
Favicon

Re: Dynamic types: GHCI works, GHC doesn't?

> 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
compilers.)

> 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
(Continue reading)


Gmane