caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Lukasz Stafiniak <lukstafi@gmail.com>
Cc: Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic recursion and GADTs
Date: Tue, 10 Dec 2013 20:07:44 +0100	[thread overview]
Message-ID: <CAPFanBEpbxsBmvygWnOWnDydmgw7JO-csZVt=xq8Ei94G6eqjw@mail.gmail.com> (raw)
In-Reply-To: <CAJMfKEW9TVbuBWwwA+6zwKS+dr0kmOW_fWDD+Z=PcT0+m7ADqw@mail.gmail.com>

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

You must not use a type annotation here ('t47), because its (implicit)
scope is above. Removing the annotation or using _ in lieu of the free type
variable solves your problem. See this recent bugreport where the same
question was raised:
  http://caml.inria.fr/mantis/view.php?id=6264


On Tue, Dec 10, 2013 at 3:24 PM, Lukasz Stafiniak <lukstafi@gmail.com>wrote:

> I have another challenge for you. Without the redundant annotations (i.e.
> with only an annotation on let-rec) it type-checks nicely. I am providing
> more annotations as an option.
> >>>
> type _ term =
>   | Lit : integer -> integer term
>   | Plus : integer term * integer term -> integer term
>   | IsZero : integer term -> boolean term
>   | If : (*∀'a.*)boolean term * 'a term * 'a term -> 'a term
>   | Pair : (*∀'a, 'b.*)'a term * 'b term -> (('a * 'b)) term
>   | Fst : (*∀'a, 'b.*)(('a * 'b)) term -> 'a term
>   | Snd : (*∀'a, 'b.*)(('a * 'b)) term -> 'b term
>  and integer
> and boolean
>
> external plus : (integer -> integer -> integer) = "plus"
> external is_zero : (integer -> boolean) = "is_zero"
> external if_then : (boolean -> 'a -> 'a -> 'a) = "if_then"
> let rec eval : type a . (a term -> a) =
>   ((function Lit i -> i | IsZero x -> is_zero (eval x)
>     | Plus (x, y) -> plus (eval x) (eval y)
>     | If (b, t, e) -> if_then (eval b) (eval t) (eval e)
>     | Pair (x, y) -> (eval x, eval y)
>     | Fst p -> let ((x, y): (a * 't47)) = eval p in x
>     | Snd p -> let ((x, y): ('t59 * a)) = eval p in y): a term -> a)
> <<<
> We get at "eval p" to the right of "let ((x, y): (a * 't47))":
> Error: This expression has type a * b#0
>        but an expression was expected of type a * b#0
>        The type constructor b#0 would escape its scope
>
>

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

  reply	other threads:[~2013-12-10 19:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-09 17:16 Lukasz Stafiniak
2013-12-09 17:24 ` Lukasz Stafiniak
2013-12-09 21:34   ` Lukasz Stafiniak
2013-12-10 13:20     ` Lukasz Stafiniak
2013-12-10 13:21       ` Lukasz Stafiniak
2013-12-10 14:24         ` Lukasz Stafiniak
2013-12-10 19:07           ` Gabriel Scherer [this message]
2013-12-10 22:43           ` Jacques Garrigue
2013-12-10 22:51             ` Lukasz Stafiniak
2013-12-10 22:55               ` Lukasz Stafiniak
2013-12-09 17:25 ` 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='CAPFanBEpbxsBmvygWnOWnDydmgw7JO-csZVt=xq8Ei94G6eqjw@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=lukstafi@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).