English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] checking for same ctor type?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-06-28 (02:40)
From: Chris Hecker <checker@d...>
Subject: [Caml-list] checking for same ctor type?

What's the right way to check if two variants have the same ctor, but
not necessarily the same values in the ctor parms?

For example, I want to check if both data_types are Strings:

type data_type =
    String of string
  | Float of float

let a = String "foo"
let b = String "bar"
let c = Float 2.0

let ctor_equal a b = ???

ctor_equal a b = true
ctor_equal a c = false

I can think of a couple definitions of ctor_equal, one using
Hashtbl.hash_param 1 1 and one using Obj.tag (which both appear to be
doing the same thing).  Both of these seem a bit cheesy and
implementation dependent.

Is there a better way?


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