From: Leo White <lwhite@janestreet.com>
To: Kenichi Asai <asai@is.ocha.ac.jp>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Question on "more general"
Date: Thu, 20 Apr 2017 10:25:03 +0100 [thread overview]
Message-ID: <CABkXwko9w6Drvu_HJtB_KtFcfk6kx1wYQE1+PoAEFBnSjSy00g@mail.gmail.com> (raw)
In-Reply-To: <20170420001502.GA65316@pllab.is.ocha.ac.jp>
[-- Attachment #1: Type: text/plain, Size: 1595 bytes --]
The expression:
let a = assert false in
fun x -> 1
is not a syntactic value, so because of the value restriction it has type:
'_a -> int
That '_a comes from the `x` parameter.
> the variable a is not used in fun x -> 1
OCaml doesn't take account of whether `a` is used in deciding if something
is a value, although if you had written:
ignore (assert false);
fun x -> 1
then it would have been a value.
I suspect the part you are missing is that generalization happens as part
of `let` (and `match`, class definitions, polymorphic record creation,
etc...). If you had written:
let a = assert false in
let f = fun x -> 1 in
f
then the type associated with `x` would have been generalized as part of
the definition of `f` although the resulting function would still have type:
'_a -> int
Regards,
Leo
On 20 April 2017 at 01:15, Kenichi Asai <asai@is.ocha.ac.jp> wrote:
> > Without looking too closely at your question I would assume that is just
> the
> > value restriction.
>
> But both in the expressions:
>
> > let a = 1 in fun x -> 1
> > let a = assert false in fun x -> 1
>
> the variable a is not used in fun x -> 1. How can the type of x be
> affected by an unused binding for a around fun x -> 1?
>
> It also seems that assert false can be used polymorphically (because
> of the relaxed value restriction?):
>
> # fun () -> let a = assert false in (a 1, a true);;
> Warning 20: this argument will not be used by the function.
> Warning 20: this argument will not be used by the function.
> - : unit -> 'a * 'b = <fun>
>
> --
> Kenichi Asai
>
[-- Attachment #2: Type: text/html, Size: 2604 bytes --]
next prev parent reply other threads:[~2017-04-20 9:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-19 10:40 Kenichi Asai
2017-04-19 10:46 ` Leo White
2017-04-20 0:15 ` Kenichi Asai
2017-04-20 9:25 ` Leo White [this message]
2017-04-20 15:13 ` Kenichi Asai
2017-05-12 13:49 ` Ivan Gotovchits
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=CABkXwko9w6Drvu_HJtB_KtFcfk6kx1wYQE1+PoAEFBnSjSy00g@mail.gmail.com \
--to=lwhite@janestreet.com \
--cc=asai@is.ocha.ac.jp \
--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