caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kaspar Rohrer <kaspar.rohrer@gmail.com>
To: caml-list@yquem.inria.fr
Subject: [Caml-list] GADT exhaustiveness check
Date: Sat, 17 Nov 2012 13:44:17 +0100	[thread overview]
Message-ID: <6E1FE11E-72C5-4AA7-B24A-7E83E139F30C@gmail.com> (raw)

Hi List

I'm messing around with the new GADT feature in OCaml 4.0, trying to write a (more or less) strongly typed EDSL. And I've run into non-exhaustive pattern-matching warnings (see below for an example). I'm pretty sure that it is just an inherent shortcoming of GADTs, not a bug. The workaround is easy as well, simply add a catch all clause with a runtime error to silence the warning, and prove manually that the offending patterns can not occur.

I tried to find more information on this topic, but without getting all academic, documentation on GADT seems sparse at best. The description of the original implementation at https://sites.google.com/site/ocamlgadt/ seems to be the most comprehensive I've found so far. And I'm not sure the information about exhaustiveness is still up to date.

It would be nice if somebody could maybe shed some more light on this.

Cheers
	Kaspar


Code that illustrates the problem:

module T :
    sig
      type 'a t
      val int : int t
    end
    =
  struct
    type 'a t = ()
    let int = ()
  end

type ('r,_) args =
  | ANil : ('r,'r) args
  | ACons : 'a * ('r,'b) args -> ('r,'a -> 'b) args

let a = ANil
let b = ACons (3, ANil)

type ('r,'a) fun' =
  | FVoid : 'r T.t -> ('r,'r) fun'
  | FLambda : 'a T.t * ('r,'b) fun' -> ('r,'a -> 'b) fun'

let f = FVoid T.int
let g = FLambda (T.int, f)

let rec apply : type r a . (r,a) fun' * (r,a) args -> unit = function
  | FVoid t, ANil -> ()
  | FLambda (t,f), ACons (_,a) -> apply (f,a)
(*
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
(FLambda (_, _), ANil)
 *)

             reply	other threads:[~2012-11-17 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17 12:44 Kaspar Rohrer [this message]
2012-11-17 17:45 ` Jacques Le Normand
2012-11-17 18:20 ` Jeremy Yallop

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=6E1FE11E-72C5-4AA7-B24A-7E83E139F30C@gmail.com \
    --to=kaspar.rohrer@gmail.com \
    --cc=caml-list@yquem.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;
as well as URLs for NNTP newsgroup(s).