You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: