Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004745OCamlOCaml generalpublic2009-03-15 19:532009-03-16 05:25
Reportersilroquen 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.11.0 
Target VersionFixed in Version3.11.1+dev 
Summary0004745: inferred type with a weak type variable that maybe shouldn't be
DescriptionHere 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 InformationNote 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0004855)
garrigue (manager)
2009-03-16 05:25

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.

- Issue History
Date Modified Username Field Change
2009-03-15 19:53 silroquen New Issue
2009-03-16 05:25 garrigue Note Added: 0004855
2009-03-16 05:25 garrigue Status new => closed
2009-03-16 05:25 garrigue Resolution open => fixed
2009-03-16 05:25 garrigue Fixed in Version => 3.11.1+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker