From: Anders Peter Fugmann <anders@fugmann.net>
To: caml-list@inria.fr
Subject: [Caml-list] Strange Gadt error
Date: Thu, 8 Oct 2015 20:46:48 +0200 [thread overview]
Message-ID: <5616BA18.8000808@fugmann.net> (raw)
Hi,
I the following example (boiled down from a real use case):
type _ elem =
| Int: int elem
let rec incr: type a. a elem -> a -> int = function
| Int -> fun i -> add i 1
and add n m = n + m
I get the error (Ocaml 4.02.3):
File "example.ml", line 5, characters 24-25:
Error: This expression has type int but an expression was expected of type
int
This instance of int is ambiguous:
it would escape the scope of its equation
I can get rid of the error by annotating the type of i in line 5 like this:
| Int -> fun (i : int) -> add i 1
^^^
Or move add above incr like this:
let rec add n m = n + m
and incr: type a. a elem -> a -> int = function
| Int -> fun i -> add i 1
Is there an explanation to why I need to give the type of i in this
case? As 'i' _must_ be an int (from the type annotation of incr),
annotating the function seems ambiguous.
/Anders
next reply other threads:[~2015-10-08 18:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-08 18:46 Anders Peter Fugmann [this message]
2015-10-08 23:17 ` Jacques Garrigue
2015-10-12 14:20 ` Anders Peter Fugmann
2015-10-13 1:41 ` Jacques Garrigue
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=5616BA18.8000808@fugmann.net \
--to=anders@fugmann.net \
--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;
as well as URLs for NNTP newsgroup(s).