Browse thread
Re: "ocaml_beginners"::[] Syntax for polymorphic methods
-
Lukasz Stafiniak
- Jacques Garrigue
[
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@m...> |
| Subject: | Re: [Caml-list] Re: "ocaml_beginners"::[] Syntax for polymorphic methods |
From: "Lukasz Stafiniak" <lukstafi@gmail.com>
> Objective Caml version 3.09.3
>
> # type pty = {pv : 'a . 'a list};;
> type pty = { pv : 'a. 'a list; }
> # let px = {pv = []};;
> val px : pty = {pv = []}
> # match px with
> {pv=[]} -> "OK"
> | {pv=5::_} -> "int"
> | {pv=true::_} -> "bool";;
> Fatal error: exception Assert_failure("typing/parmatch.ml", 784, 55)
Thanks for finding a small bug.
The code above is meaningless: only the empty list has type
forall 'a. 'a list.
Yet one could write it, and invalidate some internal invariant of the
compiler.
Now (for 3.10) this triggers an error message:
The record field label pv is polymorphic.
You cannot instantiate it in a matching.
An aside of the fix is that matching a polymorphic field with a
variable now generates a polymorphic binding.
# fun {pv=v} -> true::v, 1::v;;
- : pty -> bool list * int list = <fun>
Jacques Garrigue