Browse thread
[Caml-list] checking for same ctor type?
-
Chris Hecker
- Brian Rogoff
- Chris Hecker
- Chris Quinn
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Brian Rogoff <bpr@b...> |
| Subject: | Re: [Caml-list] checking for same ctor type? |
On Wed, 27 Jun 2001, Chris Hecker wrote: > 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 = ??? let ctor_equal a b = match a,b with String(_),String(_) | Float(_),Float(_) -> true | _,_ -> false > 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. Yes, but there's only one implementation, right? > Is there a better way? Beauty is in the eye of the beholder. -- Brian ------------------- 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