From: "Pierre CREGUT - FT.BD/CNET/DTL/MSV" <pierre.cregut@cnet.francetelecom.fr>
To: Pierre Weis <Pierre.Weis@inria.fr>
Cc: Simon Helsen <helsen@informatik.uni-tuebingen.de>, caml-list@inria.fr
Subject: Re: polymorphic recursion
Date: Tue, 22 Sep 1998 17:50:23 +0200 [thread overview]
Message-ID: <19980922175023.23586@lsun564> (raw)
In-Reply-To: <199809221506.RAA17926@pauillac.inria.fr>; from Pierre Weis on Tue, Sep 22, 1998 at 05:06:41PM +0200
Quoting Pierre Weis (Pierre.Weis@inria.fr):
> > This might be the case for OCaml, but note that SML97 disallows more
> > general type-constraints than the type apparent in the expression without
> > the constraint (cf. rule (9) and comment in the 97 Definition - p22)
>
> That's a good point. It's simple to state and understand.
This way of handling type constraints is inherited from Hope.
[...]
> Another problem is the scope of type variables in type
> constraints. What's the meaning of
>
> let f (x : 'a) (y : 'a) = y;;
>
> We may need explicit Forall keywords to express type schemes in constraints.
[...]
This has already been solved in the SML standard and even if it is not
necessarily easy to understand when formalized, this is quite intuitive :
First un occurrence of 'a in a value declaration [val valbind] is said to
be unguarded if the occurrence is not part of a smaller value declaration
within [valbind]. In this case we say that 'a occurs unguarded in the value
declaration.
Then we say that 'a is scoped at a particular occurrence O of [val valbind]
in a program if (1) 'a occurs unguarded in this value declaration, and (2)
'a does not occur unguarded in any larger value declaration containing
the occurrence O.
Old Definition of Standard ML p 20
According to this definition, the 'a's denote the same type variable in
your example.
let g (x : 'a) = let f (x:'a) = x in x
let h (x : 'a) = x
is equivalent to
let g (x : 'a) = let f (x:'a) = x in x
let h (x : 'b) = x
but not to
let g (x : 'a) = let f (x:'c) = x in x
let h (x : 'b) = x
The only risk of this solution is that you overconstrain an expression
because one of your type variable got caught in the scope of another unrelated
variable and then you get stuck with your compiler complaining about
a constraint it cannot fulfill. This is a safe risk.
--
Pierre Cregut - pierre.cregut@cnet.francetelecom.fr - +33 2 96 05 16 28
FT.CNET - DTL/MSV - 2 avenue Pierre Marzin - 22307 Lannion Cedex - France
next prev parent reply other threads:[~1998-09-22 16:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-09-21 16:30 Peter J Thiemann
1998-09-22 2:33 ` Jacques GARRIGUE
1998-09-22 9:22 ` Pierre Weis
1998-09-22 10:00 ` Simon Helsen
1998-09-22 15:06 ` Pierre Weis
1998-09-22 15:28 ` Simon Helsen
1998-09-22 16:33 ` Pierre Weis
1998-09-22 15:50 ` Pierre CREGUT - FT.BD/CNET/DTL/MSV [this message]
1998-09-22 17:14 ` Xavier Leroy
1998-09-28 9:51 ` Pierre Weis
1998-09-28 11:45 ` Peter Thiemann
1998-09-28 13:00 ` Pierre Weis
1998-10-05 14:27 ` Local definitions Anton Moscal
1998-10-12 11:39 ` Xavier Leroy
1998-10-12 17:20 ` Adam P. Jenkins
1998-10-14 13:47 ` Anton Moscal
1999-08-22 20:35 Polymorphic recursion Hongwei Xi
1999-08-23 12:19 ` Pierre Weis
2007-04-03 16:59 Loup Vaillant
2007-04-04 13:49 ` [Caml-list] " Roland Zumkeller
2007-04-04 15:13 ` Alain Frisch
2007-04-04 15:50 ` Stefan Monnier
2008-05-12 21:55 polymorphic recursion Jacques Le Normand
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=19980922175023.23586@lsun564 \
--to=pierre.cregut@cnet.francetelecom.fr \
--cc=Pierre.Weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=helsen@informatik.uni-tuebingen.de \
/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