Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:  FAQ:
To unsubscribe, mail  Archives: