* Re: Why is this not allowed?
@ 1999-12-02 11:13 Damien Doligez
1999-12-02 18:40 ` John Prevost
0 siblings, 1 reply; 4+ messages in thread
From: Damien Doligez @ 1999-12-02 11:13 UTC (permalink / raw)
To: caml-list
>From: Claudio Sacerdoti Coen <sacerdot@students.cs.unibo.it>
[...]
>can you explain me why is this not allowed?
>I can't see a problematic counterexample.
[...]
># 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.
-- Damien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why is this not allowed?
1999-12-02 11:13 Why is this not allowed? Damien Doligez
@ 1999-12-02 18:40 ` John Prevost
1999-12-03 13:50 ` Pierre Weis
0 siblings, 1 reply; 4+ messages in thread
From: John Prevost @ 1999-12-02 18:40 UTC (permalink / raw)
To: Damien Doligez; +Cc: caml-list
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why is this not allowed?
1999-12-02 18:40 ` John Prevost
@ 1999-12-03 13:50 ` Pierre Weis
0 siblings, 0 replies; 4+ messages in thread
From: Pierre Weis @ 1999-12-03 13:50 UTC (permalink / raw)
To: John Prevost; +Cc: caml-list
> 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Why is this not allowed?
@ 1999-11-30 16:07 Claudio Sacerdoti Coen
0 siblings, 0 replies; 4+ messages in thread
From: Claudio Sacerdoti Coen @ 1999-11-30 16:07 UTC (permalink / raw)
To: caml-list
Hi,
can you explain me why is this not allowed?
I can't see a problematic counterexample.
Objective Caml version 2.04
# let id x = x;;
val id : 'a -> 'a = <fun>
# let rec id' x = id x;;
val id' : 'a -> 'a = <fun>
# let rec id'' = id;;
This kind of expression is not allowed as right-hand side of `let rec'
T.I.A.
C.S.C.
--
-----------------------------------------
Real Name: Claudio Sacerdoti Coen
Address: via del Colle n.6
S. Lazzaro di Savena (BO)
Italy
e-mail: sacerdot@cs.unibo.it
-----------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1999-12-03 13:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-02 11:13 Why is this not allowed? Damien Doligez
1999-12-02 18:40 ` John Prevost
1999-12-03 13:50 ` Pierre Weis
-- strict thread matches above, loose matches on Subject: below --
1999-11-30 16:07 Claudio Sacerdoti Coen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox