Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
using sets
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1994-03-28 (17:41)
From: Pierre Weis <weis@p...>
Subject: using sets

> type Lien = {A_lien : Noeud ref ; B_lien :Noeud ref };;
> and now I would like to use sets of "Liens".
> I don't know how to define a total order over references

You cannot hope to write such a function, if it reads the contents of the
references, since further assignments to the references can change the
ordering of the references. The only way seems to compare their
adresses independantly of their contents, but due to the gc, these
adresses may change. If the gc changes these adresses consistently with
the ordering, then a piece of magic could be written, otherwise I
don't know how to deal with the problem.

However, the best solution is yours: simply add a field to compare
elements of type Lien!

Pierre Weis

PS: Have you good reasons to use records with fields containing
references, instead of records with mutable fields ? If no, just
remove the refs and add a new field to compare the Lien values: your
Lien data will be more compact than they are now, and you'll have no
more problems to compare them!