Version française
Home     About     Download     Resources     Contact us    
Browse thread
Sorted list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrej Bauer <Andrej.Bauer@f...>
Subject: Re: [Caml-list] Sorted list
tmp123@menta.net wrote:
> It seems dificult to generate an unique identifier, for this subject or any 
> other (in this sense, I feel nostalgic of the old C pointers).

You can use references for that:

type id = unit ref

(** [unique_id ()] returns a unique reference. *)
let unique_id () = ref ()

(** [equal_id id1 id2] compares two ids for equality. *)
let equal_id id1 id2 = (id1 == id2)

Now the trouble here is that you might accidentally compare id's with = 
instead of ==. If I use references to functional values then I get a 
runtime exception rather than a type error. Abstract types don't help 
either, so I am out of ideas.

There are many theoretical reasons why abstract types should have their 
own user-defined equality tests (and the user might choose not to have 
an equality test at all). Where do PL designers like Xavier stand on 
this? SML has equality types (but that's not what I am talking about).

Best regards,

Andrej