Data.Map, Data.IntMap documentation
Stefan O'Rear
stefanor at cox.net
Fri Aug 17 21:59:23 EDT 2007
On Sat, Aug 18, 2007 at 03:33:19AM +0200, Benjamin Franksen wrote:
> Adrian Hey wrote:
> > Benjamin Franksen wrote:
> >> Adrian Hey wrote:
> >>> Is there a type that is an instance of Eq,
> >>> but not Ord (or could not reasonably be made an instance of Ord)?
> >>
> >> Data.Typeable.TypeRep
> >
> > Interesting problem, but I don't see any reason why this could not
> > be an instance of Ord.
>
> I asked this question once and got as answer (from one of the Simons, IIRC)
> that exposing the obvious Ord instance would break referential
> transparency: there is no guarantee that the integer keys and therefore the
> order among TypeReps is the same for different runs, even of the same
> program.
>
> This (counter-)example may be irrelevant for the discussion at hand or not.
> Anyway, you asked for one...
There's nothing stoping you from writing
instance Ord TypeRep where compare = comparing show
STRef could also be cheaply made Ord, but at the cost of a bit more
work; the idea is to notice that GHC's compacting garbage collector
never reorders "abstract heap addreses", a concept I just made up which
starts at 0 and increases as new blocks are added to the heap; so one
must create an inverse map from physical blocks (which are aligned, so
finding metadata is just a bitmask) to abstract block numbers, and then
use that information to implement a compareAddress# primop suitable for
{ST,IO}Reff, TVar, and {ST,IO}{U,}Array (in the latter case, you would
do address comparison for pinned arrays and arbitrarily declare all
pinned arrays larger than all unpinned arrays).
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/libraries/attachments/20070817/470d92a1/attachment.bin
More information about the Libraries
mailing list