|Anonymous | Login | Signup for a new account||2016-06-25 08:56 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0000109||OCaml||OCaml general||public||2000-05-12 01:32||2000-05-24 03:38|
|Target Version||Fixed in Version|
|Summary||0000109: Polymorphic Variant generates comiler exception|
|Description||Full_Name: David Clarke|
Submission from: cache2.uwn.unsw.edu.au (22.214.171.124)
The following code (which is invalid):
let f x = match x with `spam 3 -> 29 | `spam "spat" -> 23;;
causes the compiler to halt and generate the following error message:
Uncaught exception: File "typing/parmatch.ml", line 0, characters 16649-16661:
|Tags||No tags attached.|
> Full_Name: David Clarke
> Version: 3.00
> OS: SunOS
> Submission from: cache2.uwn.unsw.edu.au (126.96.36.199)
> The following code (which is invalid):
> let f x = match x with `spam 3 -> 29 | `spam "spat" -> 23;;
> causes the compiler to halt and generate the following error message:
> Uncaught exception: File "typing/parmatch.ml", line 0, characters
> Assertion failed
Well, the current definition is a bit ambiguous about what is valid or not.
In particular, the definition
let f1 = function `spam 3 -> 29
let f2 = function `spam "spat" -> 23
let f x = f1 x + f2 x
val f1 : [< `spam of int] -> int = <fun>
val f2 : [< `spam of string] -> int = <fun>
val f : [< `spam of string & int] -> int = <fun>
is explicitly described as valid, while it is of course meaningless.
The bug you report could be solved in two ways:
* either decide that this is valid, and just produces an unusable function.
This requires compiling it to some arbitrary code, and would make some
parts of the compiler rather dirty.
* or explicitly say that while variant types with conjunctive types are allowed
in expressions, they are not allowed in patterns. This gives a more
intuitive behaviour, with useful error messages.
I think that the second solution is better, and I have implemented it
in the CVS version, by using a stricter form of unification on pattern types.
However this gives raise to some philosophical questions about what are the
theoretical properties expected when typing patterns, and how this interacts
with the typing of expressions. This change is subject to theory and
Fixed on 2000-05-12 by Jacques (changed typing of variants in patterns, to allow
only one type for matched tags).
|2005-11-18 10:13||administrator||New Issue|
|Copyright © 2000 - 2011 MantisBT Group|