This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Re: polymorphic recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 1998-09-22 (16:41) From: Pierre CREGUT - FT.BD/CNET/DTL/MSV Subject: Re: polymorphic recursion
```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

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