Browse thread
[Caml-list] Odd Type Checking Problem
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alain Frisch <frisch@c...> |
| Subject: | [Caml-list] Type variables (was: Odd Type Checking Problem) |
Hello,
On Wed, 6 Feb 2002, I wrote:
> I guess this is a problem of understanding type variable scoping rules.
Actually, I feel myself somewhat confused with implicit introduction and
scoping of type variables.
These one are refused:
let f (x : 'a) = let module M = struct exception X of 'a end in ();;
let f (x : 'a) = let module M = struct type t = 'a end in ();;
This is accepted:
let f (x : 'a) =
let module M =
struct
type t constraint t = 'a;;
exception X of t;;
end in ();;
but is quite useless, since both:
let f (x : 'a) =
let module M =
struct
type t constraint t = 'a;;
exception X of t;;
raise (X x);;
end in ();;
and
let f (x : 'a) =
let module M =
struct
type t constraint t = 'a;;
exception X of t;;
end in raise (M.X x);;
are rejected by the type checker.
(in "constraint ...", no new variable is introduced)
Another example:
let f (x : 'a) =
let module M =
struct
type u = { a : 'a }
end in ();;
=> rejected (Unbound type parameter 'a)
(and accepted by
"Objective Caml version 3.04+1 with explicit polymorphism (2002-01-07)",
but with a different meaning that one could expect)
Is there a way to use a type variable such as the 'a above to define
types in a local structure ?
-- Alain
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr