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

inferred type with a weak type variable that maybe shouldn't be #4745

Closed
vicuna opened this issue Mar 15, 2009 · 1 comment
Closed

inferred type with a weak type variable that maybe shouldn't be #4745

vicuna opened this issue Mar 15, 2009 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 15, 2009

Original bug ID: 4745
Reporter: silroquen
Status: closed (set by @garrigue on 2009-03-16T04:25:41Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.0
Fixed in version: 3.11.1+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @yakobowski

Bug description

Here is a simple linked list type:

type 'a linked_list = 'a node option
and 'a node = {
value : 'a;
next : 'a linked_list;
}

and three apparently equivalent functions to find the linked list's last node:

let rec find_end_a = function
| None -> None
| Some {next = None} as li -> li
| Some node -> find_end_a node.next

let rec find_end_b = function
| None -> None
| Some {next = None} as li -> li
| Some {next = n} -> find_end_b n

let rec find_end_c = function
| None -> None
| Some {next = None} as li -> li
| Some {next = Some n} -> find_end_c (Some n)

Note that the inferred type for find_end_a and find_end_b is
'_a linked_list -> '_a node option
but, for find_end_c:
'a node option -> 'a node option

It seems like all three functions should have the type of find_end_c.

Additional information

Note that if the linked_list type is eliminated, so instead

type 'a node = {
value : 'a;
next : 'a node option
}

then the functions find_end_* all have type
'a node option -> 'a node option
as expected.

@vicuna
Copy link
Author

vicuna commented Mar 16, 2009

Comment author: @garrigue

Thanks for pointing this subtle bug, that appears only in the toplevel.
This was due to side-effects to types during compilation...
Solved by taking clean copies when needed.

@vicuna vicuna closed this as completed Mar 16, 2009
@vicuna vicuna added the bug label Mar 20, 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