caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: Kenichi Asai <asai@is.ocha.ac.jp>
Cc: Leo White <lwhite@janestreet.com>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Question on "more general"
Date: Fri, 12 May 2017 09:49:25 -0400	[thread overview]
Message-ID: <CALdWJ+xLHzqHkCh1hs8HmAGh4+tGJXt9Vdpesc4BhaqdxbPr=g@mail.gmail.com> (raw)
In-Reply-To: <20170420151331.GA3452@pllab.is.ocha.ac.jp>

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

A small update.

But before the update, let me clarify the original reason, why the
expression `let a = assert false in fun x -> 1` is not generalized. The
reason is because the `assert false` is not nonexpansive (sorry for the
double negation). A nonexpansive value, in OCaml compiler parlance, is a
value that has "no _observable_ side effects". The `assert false` is
currently typed as a special expression, that is assumed to have a side
effect (i.e., it is expansive).  Thus, it is basically treated the same as
`let a = print_int 1 in fun x -> 1` that is also not generalized, as the
evaluation of the `print_int 1 in fun x -> 1` has some effect.

Apparently, the assumption that `assert false` is expansive was too
conservative, as it was already subsumed (in some cases) with the value
restriction relaxation. So it will be relaxed soon, see GPR#1142 [1]. And
soon both of your functions will have the same type.



[1]: https://github.com/ocaml/ocaml/pull/1142

On Thu, Apr 20, 2017 at 11:13 AM, Kenichi Asai <asai@is.ocha.ac.jp> wrote:

> Thank you!  That's very clear.  So instead of writing assert false, if
> I could write a "value" of type 'a, then the type of x becomes 'a.
>
> I confirmed it with the following file:
>
> --------------------------------
> let v = assert false
>
> let g1 = let a = v in
>          let f = fun x -> 1 in
>          f
>
> let g2 = let a = assert false in
>          let f = fun x -> 1 in
>          f
> --------------------------------
>
> If I see the types of variables via "ocamlc -i", I obtained:
>
> val v : 'a
> val g1 : 'a -> int
> val g2 : '_a -> int
>
> Thank you again!
>
> --
> Kenichi Asai
>
> --
> 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: 2929 bytes --]

      reply	other threads:[~2017-05-12 13:49 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
2017-04-20 15:13       ` Kenichi Asai
2017-05-12 13:49         ` Ivan Gotovchits [this message]

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='CALdWJ+xLHzqHkCh1hs8HmAGh4+tGJXt9Vdpesc4BhaqdxbPr=g@mail.gmail.com' \
    --to=ivg@ieee.org \
    --cc=asai@is.ocha.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=lwhite@janestreet.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).