[
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: | Jacques Garrigue <garrigue@k...> |
| Subject: | Re: Strange type error |
From: Claudio Sacerdoti Coen <sacerdot@students.cs.unibo.it>
> let a.mli be
>
> type 'a section_path = { x : int; }
> and mind_section_path = [ `MIND] section_path
> type const_section_path = [ `CONST] section_path
>
> and b.mli be
>
> type 'a section_path = { x : int; }
> type mind_section_path = [ `MIND] section_path
> type const_section_path = [ `CONST] section_path
>
> b.mli is compiled without problems, but for a.mli I get
>
> File "prova.mli", line 3, characters 26-35:
> This type [ `CONST] should be an instance of type [ `MIND]
>
> that seems nonsense to me. Someone could explain the error?
For a long time, the answer was: "this is not a bug, this is a
feature." (cf. this mailing list more than 1 year ago)
That is, in recursive type definitions, as in recursive value
definitions, the polymorphism is only given after a definition block
is finished. As a result, the definition in a.mli actually means:
type 'a section_path = { x : int } constraint 'a = [ `MIND]
You can see it by doing `ocamlc -i -c a.mli'.
In the current version (upcoming 3.01), this problem is solved:
type definitions are assumed to be polymorphic, and if you want the
above behavior you must explicitly request it. As a result a.mli and
b.mli become equivalent. So we can now assume that this was a bug.
Cheers,
Jacques Garrigue
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>