Version française
Home     About     Download     Resources     Contact us    
Browse thread
on objects, equality and playing nicely with the stdlib
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Peng Zang <peng.zang@g...>
Subject: Re: [Caml-list] on objects, equality_and_playing_nicely_with_the stdlib
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Thursday 29 May 2008 04:13:20 am Christophe Raffalli wrote:
> Via Custom block (section 18.9.1 of the manual), you could create a functor
> with the following shape (I did not check my syntax):
>
> module type Quotient =
>   type t
>   type qt
>   val class : t -> qt
>   val get_representent : qt -> t
> end
>
> module type Equivalence =
>   type t
>   val compare : t -> t -> int
> end
>
> module Make_Quotient (R : Equivalence) : Quotient with type t = R.t
>
> Such that (class x) builds a custom block with
> the given compare as comparison function ...
> You can add hash and serialization to the Equivalence type too ...
>
> It is a pity we have to do that from C, this should be the default way
> to bridge the gap between polymorphic comparison and specific comparison.
> (and PML will provide a buildin class constructor in the near future).
>
> Hope this helps,
> Christophe

This is very interesting.  I've never read that part of the manual.  It's 
probably too much overhead for me, so I'll resort to cut + paste first and 
see how it goes.  Thanks,

Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFIPq66fIRcEFL/JewRAh2mAKCjCBE3OLYeAudddf5qCoF5jtKmLgCfTRWP
Q5xoPoXccaD512zj99mDs7Q=
=X2pn
-----END PGP SIGNATURE-----