From: Pierre Weis <Pierre.Weis@inria.fr>
To: prevost@maya.com (John Prevost)
Cc: caml-list@inria.fr
Subject: Re: Why is this not allowed?
Date: Fri, 3 Dec 1999 14:50:47 +0100 (MET) [thread overview]
Message-ID: <199912031350.OAA04967@pauillac.inria.fr> (raw)
In-Reply-To: <87n1rtb2z7.fsf@isil.maya.com> from "John Prevost" at Dec 2, 99 01:40:44 pm
> Damien Doligez <Damien.Doligez@inria.fr> writes:
>
> > ># let rec id'' = id;;
> > >This kind of expression is not allowed as right-hand side of `let rec'
> >
> > Because we don't know how to compile "let rec x = x" or
> > let rec x = y
> > and y = x
> >
> > Moreover, you can just remove the "rec" and it works. It is possible
> > to implement "let rec var1 = var2", but the usefulness is quite small
> > compared to the amount of code we would need to write.
>
> Well, you can't quite. Because of the value restriction, id'' defined
> like this:
>
> let id'' = id;;
>
> has type:
>
> id'' : '_a -> '_a
>
> (That is, it'll only work for a single type.)
>
> John.
There is some confusion here: since «id» is an expression that is a
mere variable, it is not expansive; hence it can be safely generalized;
hence it can be used with different uncompatible types:
# let id x = x;;
val id : 'a -> 'a = <fun>
# let id'' = id;;
val id'' : 'a -> 'a = <fun>
# id'' 1, id'' true;;
- : int * bool = 1, true
Rule of thumb concerning the polymorphism generalisation restriction:
the restriction is performed by matching the right hand side expression e
of a let definition:
1 if e is a constant, a variable expression, a function (that is a
syntactically explicit function, introduced by the keyword fun or
function), or a constructor application, then its type can safely be
generalised.
2 otherwise the type of e is not generalized.
Condition 1 is a rough approximation of the property ``the execution
of e cannot create a polymorphic mutable value''; in practice,
condition 2 means that if e is a function application then its type is
not generalized.
Best regards,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
next prev parent reply other threads:[~1999-12-03 13:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-02 11:13 Damien Doligez
1999-12-02 18:40 ` John Prevost
1999-12-03 13:50 ` Pierre Weis [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-11-30 16:07 Claudio Sacerdoti Coen
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=199912031350.OAA04967@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=prevost@maya.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).