* [Caml-list] Polymorphic Set
@ 2001-12-19 19:08 Vincent Barichard <Vincent Barichard
2001-12-19 19:47 ` Brian Rogoff
0 siblings, 1 reply; 2+ messages in thread
From: Vincent Barichard <Vincent Barichard @ 2001-12-19 19:08 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Polymorphic Set
2001-12-19 19:08 [Caml-list] Polymorphic Set Vincent Barichard <Vincent Barichard
@ 2001-12-19 19:47 ` Brian Rogoff
0 siblings, 0 replies; 2+ messages in thread
From: Brian Rogoff @ 2001-12-19 19:47 UTC (permalink / raw)
To: Vincent Barichard <Vincent Barichard; +Cc: caml-list
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=X-UNKNOWN, Size: 1490 bytes --]
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-12-20 12:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-19 19:08 [Caml-list] Polymorphic Set Vincent Barichard <Vincent Barichard
2001-12-19 19:47 ` Brian Rogoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox