caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: David RENAULT <renault@labri.fr>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] GADTs : a type variable cannot be deduced
Date: Fri, 25 Oct 2013 14:25:46 +0200	[thread overview]
Message-ID: <CAPFanBEW=uEY2ZFTGG8ZmHsZpLZdi-Hfc=FpMABHC12Y_00UWA@mail.gmail.com> (raw)
In-Reply-To: <526A5F2A.6060904@labri.fr>

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

The problem is with the assumed injectivity of the abstract type 'a succ.
You should write:

  type 'a succ = Succ

then everything works out.

Injectivity was assumed to hold for types *defined* to be abstract, but
does not hold for types *declared* as abstract (That may have been defined
concretely as just "int" in their implementation). For consistency,
defined-abstract type are no more assumed to be injective, so you should
always use a constructor for that (using a constructor makes your type
nominal/generative/fresh, which enforces injectivity).

Remark: I'll let you work out while it would be problematic to consider a
('a succ succ nat)-matching branch as dead when matching over a ('a succ
nat) value, under the definition (type 'a succ = int).


On Fri, Oct 25, 2013 at 2:08 PM, David RENAULT <renault@labri.fr> wrote:

>
>                 Hi,
>
> I was experimenting on GADTs and phantom types and was using the usual
> encoding for naturals, as well as a classic implementation of the
> associated singleton type :
>
> type zero
> type 'a succ
> type _ nat =
>   | Zero : zero nat
>   | Succ : 'a nat -> ('a succ) nat
>
> With ocamlc 4.01.0, this fails to compile with the following error
> message :
>
> Error: In this definition, a type variable cannot be deduced
>        from the type parameters.
>
> This is strange, because this code compiled pretty well with ocamlc
> 4.00.1. Of course, it is possible to modify the code to make it compile
> by replacing the type variables by underscores, but the resulting type
> is incorrect :
>
> type _ nat =
>   | Zero : zero nat
>   | Succ : _ nat -> (_ succ) nat
> (* type _ nat = Zero : zero nat | Succ : 'b nat -> 'a succ nat *)
>
> Succ Zero;; (* 'a succ nat = Succ Zero, should be "zero succ nat" *)
>
> I failed to find in the Changelog the modification that led to this
> behavior, and nothing really simple about the error message showed up.
> The following file seems to prove that the problem appears in various
> other cases :
>
> http://caml.inria.fr/svn/ocaml/trunk/testsuite/tests/typing-gadts/pr5985.ml
>
> Is the code I am writing incorrect ? (for reference, the same code in
> Haskell (with ghc) works as expected)
>
>                 RENAULT David
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

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

  reply	other threads:[~2013-10-25 12:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-25 12:08 David RENAULT
2013-10-25 12:25 ` Gabriel Scherer [this message]
2013-10-29 14:17   ` David RENAULT
2013-10-29 14:47     ` Gabriel Scherer

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='CAPFanBEW=uEY2ZFTGG8ZmHsZpLZdi-Hfc=FpMABHC12Y_00UWA@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=renault@labri.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).