From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Abdallah Saffidine <abdallah.saffidine@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] How to use GADTs across modules in OCaml without raising warnings?
Date: Tue, 13 Oct 2015 15:10:01 +0900 [thread overview]
Message-ID: <57AB371C-5E6C-4F1F-BB35-2DB8F456CB8B@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CALx9x4dgS_1_SFGu3Qn77UH8dw957A-s2h44Gri4UbRRBRQ6FQ@mail.gmail.com>
On 2015/10/13 14:27, Abdallah Saffidine wrote:
>
> Hi all,
>
> I am reposting this SO question. I suspect there might be a bug in the implementation of Warning 8.
>
> Thanks,
> Abdallah
>
> I have two files: gadt1.ml and gadt2.ml and the second depends on the first.
>
> gadt1.ml:
>
> type
> never
>
> type _ t1 = A1 : never t1 | B1 :
> bool t1
>
> type _ t2 = A2 : string t2 | B2 :
> bool t2
>
> let get1 : bool t1 -> bool = function B1 -> true
> let get2 : bool t2 -> bool = function B2 -> true
> gadt2.ml:
>
> let get1 : bool Gadt1.t1 -> bool = function Gadt.B1 -> true
> let get2 : bool Gadt1.t2 -> bool = function Gadt.B2 -> true
> when I compile using ocaml 4.02.3 (ocamlbuild gadt2.native), I get a warning 8 about the function Gadt2.get1 not being exhaustive. I am quite puzzled that Gadt2.get1 raises a warning while Gadt1.get1 and Gadt2.get2 don't.
>
> My assumption was that the empty type never cannot be equal to bool so Gadt2.get1 should not raise a warning. On the other hand, if I call Gadt2.get1 with argument A1, I get a type error (as desired). Is the warning expected behaviour or a bug? What did I miss?
A explained by Stefan, abstract types coming from other modules cannot be proved distinct.
Only predefined types such as string or array are handled specially.
The simplest solution is to add a constructor to your type:
type never = Never
Better to do it when in the same module too.
Jacques Garrigue
prev parent reply other threads:[~2015-10-13 6:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-13 5:27 Abdallah Saffidine
2015-10-13 6:06 ` Stefan Holdermans
2015-10-13 6:09 ` Philippe Veber
2015-10-13 6:15 ` Ben Millwood
2015-10-13 9:45 ` Jeremy Yallop
2015-10-14 2:13 ` Abdallah Saffidine
2015-10-13 6:10 ` Jacques Garrigue [this message]
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=57AB371C-5E6C-4F1F-BB35-2DB8F456CB8B@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=abdallah.saffidine@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