caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Milan Stanojević" <milanst@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] constructor disambiguation for gadts
Date: Wed, 8 Oct 2014 12:29:47 +0900	[thread overview]
Message-ID: <43F352EF-1F58-4CE3-8EA5-91D61EBBA751@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAKR7PS9DnFanOxLgiCusp4LPQY64B-5SU2Bwd_hLYqb81k5Q9A@mail.gmail.com>

On 2014/10/08 01:14, Milan Stanojević wrote:
> 
> I was wondering what are technical difficulties that prevent
> constructor disambiguation for GADTs?
> 
> I got an interesting error today, where it is clear that compiler
> knows the type but because it is GADT it is still asking me to qualify
> the constructor.
> 
> Here is the simple example.
> module A : sig
>  type _ t =
>    | I : int t
>    | S : string t
> end = struct
>  type _ t =
>    | I : int t
>    | S : string t
> end
> 
> let add : type a . a A.t -> a -> a -> a =
>  fun w a1 a2 ->
>    match w with
>    | I -> a1 + a2
>    | S -> String.concat "" [a1; a2]
> ;;
> 
> I get File "foo.ml", line 14, characters 6-7:
> Error: The GADT constructor I of type A.t must be qualified in this pattern.
> 
> I'm not sure what extra information I'm giving to the type checker by
> qualifying the constructor.

Typing of GADT patterns follows a slightly different path, which makes
harder to insert constructor disambiguation.
To be more precise, the type-checker first looks at the patterns, and
tries to guess whether there are some GADT constructors inside it.
If some constructors are ambiguous, it may guess wrongly that there
are none, and take the non-GADT path, to find later that it should have
taken the GADT path.

Jacques Garrigue

  reply	other threads:[~2014-10-08  3:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 16:14 Milan Stanojević
2014-10-08  3:29 ` Jacques Garrigue [this message]
2014-10-08 16:05   ` Milan Stanojević
2014-10-14 12:34 ` Goswin von Brederlow

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=43F352EF-1F58-4CE3-8EA5-91D61EBBA751@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=milanst@gmail.com \
    /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).