Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic Variant generates comiler exception #2448

Closed
vicuna opened this issue May 11, 2000 · 2 comments
Closed

Polymorphic Variant generates comiler exception #2448

vicuna opened this issue May 11, 2000 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented May 11, 2000

Original bug ID: 109
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: David Clarke
Version: 3.00
OS: SunOS
Submission from: cache2.uwn.unsw.edu.au (129.94.6.29)

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:
Assertion failed

@vicuna
Copy link
Author

vicuna commented May 12, 2000

Comment author: administrator

Full_Name: David Clarke
Version: 3.00
OS: SunOS
Submission from: cache2.uwn.unsw.edu.au (129.94.6.29)

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:
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
implementation improvements.

Jacques Garrigue

@vicuna
Copy link
Author

vicuna commented May 24, 2000

Comment author: administrator

Fixed on 2000-05-12 by Jacques (changed typing of variants in patterns, to allow
only one type for matched tags).

@vicuna vicuna closed this as completed May 24, 2000
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant