Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ashish Agarwal <agarwal1975@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] OR-patterns with GADTs
Date: Fri, 21 Nov 2014 13:39:09 -0500	[thread overview]
Message-ID: <CAMu2m2K5Xy2nEdZb1uDC1U5NS2rDRCjx5rnPegyK=o98xgEW8g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

The following works fine:

type foo
type bar
type _ t =
| Foo : string -> foo t
| Bar : string -> bar t

let to_string : type a . a t -> string = function
  | Foo x -> x
  | Bar x -> x


However, if you try to avoid the redundant code of the two branches, you
get a compile error:

let to_string : type a . a t -> string = function
  | Foo x
  | Bar x -> x

Error: This pattern matches values of type foo t
       but a pattern was expected which matches values of type a t
       Type foo is not compatible with type a

Is there a real reason for this?

[-- Attachment #2: Type: text/html, Size: 915 bytes --]

             reply	other threads:[~2014-11-21 18:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 18:39 Ashish Agarwal [this message]
2014-11-21 21:04 ` Leo White
2014-11-22 12:44   ` Ashish Agarwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMu2m2K5Xy2nEdZb1uDC1U5NS2rDRCjx5rnPegyK=o98xgEW8g@mail.gmail.com' \
    --to=agarwal1975@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox