From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p3UKKHtD006860 for ; Sat, 30 Apr 2011 22:20:17 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtMBAFNuvE3RVdy2mGdsb2JhbACmDwgUAQEBAQEICQ0HFCWIcaA8inyCKoQDNIheAQEDBoV6BI55iBeCIzuDLw X-IronPort-AV: E=Sophos;i="4.64,294,1301868000"; d="scan'208";a="82074193" Received: from mail-vx0-f182.google.com ([209.85.220.182]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Apr 2011 22:20:11 +0200 Received: by vxc34 with SMTP id 34so6726925vxc.27 for ; Sat, 30 Apr 2011 13:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=IHJZ7FhAQ6Lnk+6Bmo7ruL63ggwOzrHhRfXIt7ZISL0=; b=c6ILIqE8xyoLYqPHgylnUfRBNaopNWh7mD+ovAHaHymPnENN+lClbDU7uBn9JH/Irx w9xwTXvvlDiM1VsxPYSmOZXJ3ObcQjZmOEHakSjE3Rpo8AY0oGV/r1+oc/c+baaV2xgx B6cs8usIMxa29ujXVWLksWs46hr2/d/q7YZRM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=UbpyaLV0amkmkGcSkwki22DbnXqBkg6fCw2jkV2vm0tplnt0Hb1jkBJIAUWsVtqRPb UeXWNbDDwh/4IqPog0egUnGY11bqb5bzyUMOhnG2GUFNEduLn0FvvP7uJICFVRVn7Ois BdzT9rroxu/eeIZxz7+1WE9afKEiTESFL+h8k= Received: by 10.52.175.195 with SMTP id cc3mr3809063vdc.242.1304194810069; Sat, 30 Apr 2011 13:20:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.114.5 with HTTP; Sat, 30 Apr 2011 13:19:50 -0700 (PDT) In-Reply-To: <4746acd6-ddad-498c-a535-a3bfdcb5fec7@email.android.com> References: <164004794.892685.1304067487325.JavaMail.root@zmbs2.inria.fr> <20110429093355.GA25892@yquem.inria.fr> <4746acd6-ddad-498c-a535-a3bfdcb5fec7@email.android.com> From: Gabriel Scherer Date: Sat, 30 Apr 2011 22:19:50 +0200 Message-ID: To: "craff73@gmail.com" Cc: luc.maranget@inria.fr, Dmitry Bely , caml-list@inria.fr Content-Type: multipart/alternative; boundary=bcaec51a7ec65f43d504a2288452 Subject: Re: [Caml-list] Comparing variant types --bcaec51a7ec65f43d504a2288452 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > > You want to avoid code size quadratic in the number of constructors. Which > is possible: > let cmp x y =3D match x, y with > A, A -> true > | A, _ | _, A -> false > | B, B -> true > | B, _ | _, B -> false With one twist though: if done that way for (type foo =3D A | B), the last = (_, B) pattern is actually redundant. If you want to avoid getting a warning here, you should comment it out or remove it: let cmp x y =3D match x, y with | A, A -> true | A, _ | _, A -> false | B, B -> true | B, _ (*| _, B*) -> false That's the style I use. On Sat, Apr 30, 2011 at 3:43 PM, craff73@gmail.com wrote: > Hello, > > You want to avoid code size quadratic in the number of constructors. Which > is possible: > > let cmp x y =3D match x, y with > A, A -> true > | A, _ | _, A -> false > | B, B -> true > | B, _ | _, B -> false > ... > > Cheers > Christophe > > -- > Envoy=E9 de mon t=E9l=E9phone Android avec K-9 Mail. Excusez la bri=E8vet= =E9. > > --bcaec51a7ec65f43d504a2288452 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
You want to avoid code size quadratic in the number of constructors. Which = is possible:
=A0
let cmp x y =3D match x, y with
A, A -> true
| A, _ | _, A -> f= alse
| B, B -> true
| B, _ | _, B -> false

With one twist though: if done that way for (type foo =3D A | = B), the last (_, B) pattern is actually redundant. If you want to avoid get= ting a warning here, you should comment it out or remove it:

=A0=A0let cmp x y =3D match x, y with
=A0=A0|= A, A -> true
=A0=A0| A, _ | _, A -> false
=A0=A0= | B, B -> true
=A0=A0| B, _ (*| _, B*) -> false
<= br>
That's the style I use.

On Sat, Apr 30, 2011 at 3:43 PM, craff73@gmail.com <craff73@gmail.com> wrote:
=
Hello,

You want to avoid code size quadratic in the number of constructors. Which = is possible:

let cmp x y =3D match x, y with
A, A -> true
| A, _ | _, A -> false
| B, B -> true
| B, _ | _, B -> false
...

Cheers
Christophe

--
Envoy=E9 de mon t=E9l=E9phone Android avec K-9 Mail. Excusez la bri=E8vet= =E9.


--bcaec51a7ec65f43d504a2288452--