Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006478OCamlOCaml typingpublic2014-07-05 21:482014-09-14 21:48
Reporterlpw25 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version4.02.0+dev 
Target Versionafter-4.02.1Fixed in Version 
Summary0006478: approx_type ignores structural types
Description`approx_type` (which approximates the type of a constraint in a recursive definition) does not handle structural types. This can lead to some surprising behaviour, since using an alias of a structural type does work.

For example:

    Process ocaml-toplevel finished
            OCaml version 4.03.0+dev0-2014-05-12

    # #warnings "-10";;

    # let k = object method m : 'a. 'a -> 'a = fun x -> x end;;
    val k : < m : 'a. 'a -> 'a > = <obj>

    # let rec x =
        lazy (x#m ());
        lazy (x#m "hello");
        (k : < m : 'a. 'a -> 'a >);;
          Characters 45-52:
          lazy (x#m "hello");
                    ^^^^^^^
    Error: This expression has type string but an expression was expected of type
             unit

    # type t = < m : 'a. 'a -> 'a >;;
    type t = < m : 'a. 'a -> 'a >

    # let rec x =
        lazy (x#m ());
        lazy (x#m "hello");
        (k : t);;
          val x : t = <obj>

Ideally, the constraints in recursive definitions would be properly typed during approximation, although I assume there is some reason this is not already the case.

Even if there is a good reason this cannot be done, it is potentially confusing, so I thought it was worth creating an issue for.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0011789)
garrigue (manager)
2014-07-06 02:59

Indeed, there is something wrong here.
I don't know why approx_type handles named types to start with: originally it was intended for labels and optional arguments.
(0012124)
doligez (administrator)
2014-09-14 21:48

I may be totally wrong, but I seem to remember that approx_type was extended to get better type errors for let rec.

- Issue History
Date Modified Username Field Change
2014-07-05 21:48 lpw25 New Issue
2014-07-06 02:59 garrigue Note Added: 0011789
2014-07-06 02:59 garrigue Assigned To => garrigue
2014-07-06 02:59 garrigue Status new => confirmed
2014-07-11 13:20 doligez Target Version => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-14 21:48 doligez Note Added: 0012124
2014-09-14 21:48 doligez Target Version undecided => after-4.02.1


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker