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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] Polymorphic Set
Hi,
    You can copy the source code of Set and make a new Polyset module.
I'll start, and the rest should be clear

module type OrderedType =
  sig
    type 'a t
    val compare: 'a t -> 'a t -> int
  end

module type S =
  sig
    type 'a elt
    type 'a t
    ...
  end

module Make(Ord: OrderedType) =
  struct
    type 'a elt = 'a Ord.t
    type 'a t = Empty | Node of 'a t * 'a elt * 'a t * int
    ...
   end

I hope that helps.

-- Brian

On Wed, 19 Dec 2001, Vincent Barichard <Vincent Barichard wrote:

>
> Hi,
>
> Is there a way in OCAML to create polymorphic Set (as for List) ?
> I've tried the following code, but ocaml don't like.
>
> 	module MySet = Set.Make (struct
> 		type t = ('a * float)
> 		let compare = function (_, valx) -> function (_, valy) ->
> 			if valx < valy then 1
> 			else if valx > valy then -1
> 			else 0
> 	end)
>
> Anybody has an idea on how to do ?
>
> Thanks for your help,
>
> Vincent
>
> --
> Vincent Barichard
> Métaheuristiques et Optimisation Combinatoire
> Faculté des Sciences d'Angers
> Tel : 02 41 73 52 06
> -------------------
> Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
> To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr
>
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr