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-29 (13:12)
From: Chris Quinn <cq@h...>
Subject: Re: [Caml-list] checking for same ctor type? is fine for nullary constructors or where you don't mind the performance hit of the function recursing into the structure of the arguments.

A more efficient equality predicate that is really just a cut down version of [compare]:

module Kludge =
    let cmp (a: 't) (b: 't) =
      let a' = Obj.repr a and b' = Obj.repr b in
      match Obj.is_block a', Obj.is_block b' with
      | true,true ->
          Obj.tag a' = Obj.tag b'
      | false,false ->
          a' = b'
      | _ -> false

It of course relies on the physical representation of sum types.
It has the merit of working on a type of any number of constructors, but the mis-merit of also operating over functions for instance!
To constrain such a comparison to sum types would require it to be built into the compiler.

Chris Q.
Bug reports:  FAQ:
To unsubscribe, mail  Archives: