[Haskell-cafe] Re: [Haskell] Re: Global Variables and IOinitializers

Simon Peyton-Jones simonpj at microsoft.com
Mon Nov 29 10:09:53 EST 2004


| > In fact GHC at least *already* generates a unique integer for each
| > TypeRep. A good idea, since it means comparisons can be done in unit
| > time. Thus indexing can be done trivially using this integer as a
| > hash function.
| 
| Yes, I have seen this in the code, too. The Ord and Typeable instances
| should be trivial.

Take care here.  There is no guarantee that the unique number generated
will be the same in each run.  So if you have Ord Typeable, this program
may give unpredictable results:

main = print (typeOf True < typeOf 'x')

This unfortunate observabilty of an ordering (or hash value) that is
needed only for efficient finite maps, is very annoying.  I wish I knew
a way round it.  As it is we can pick
	a) expose Ord/Hash, but have unpredictable results
	b) not have Ord/Hash, but have inefficient maps

Simon



More information about the Haskell-Cafe mailing list