Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005790OCamlOCaml typingpublic2012-10-15 15:132012-10-16 12:09
Reporterlealanko 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version4.00.0 
Summary0005790: Polymorphic field values no longer generalizable with (type t)
DescriptionPreviously, in 3.12, one could use "fun (type t) ->" in front of an expression to keep it general enough for assignment in a polymorphic field:

        Objective Caml version 3.12.1

# type t = { x : 'r . 'r -> 'r };;
type t = { x : 'a. 'a -> 'a; }
# let id x = x;;
val id : 'a -> 'a = <fun>
# { x = id id };;
Error: This field value has type 'a -> 'a which is less general than
         'b. 'b -> 'b
# { x = fun (type r) -> id id };;
- : t = {x = <fun>}

However, in 4.00 this no longer works:

        OCaml version 4.00.1

# type t = { x : 'a . 'a -> 'a };;
type t = { x : 'a. 'a -> 'a; }
# let id x = x;;
val id : 'a -> 'a = <fun>
# { x = fun (type a) -> id id };;
Error: This field value has type 'b -> 'b which is less general than
         'a. 'a -> 'a

In my actual code, the field does not have a function type, so eta-expansion is not an option.
Steps To Reproducetype t = { x : 'r . 'r -> 'r }
let id x = x
let _ = { x = fun (type r) -> id id }
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0008260)
garrigue (manager)
2012-10-16 10:39
edited on: 2012-10-16 10:56

Actually, the wrong one here is 3.12.1.
This code is clearly unsound.
Here is an example accepted by 3.12.1 but refused by 4.00.0

type t = { x : 'r . 'r -> 'r };;
let id x = x;;
let id' f = let r = ref [] in
  fun x -> let y = if !r = [] then x else List.hd !r in r := [x]; f y;;
let t = { x = fun (type r) -> id' id };;
t.x 3;;
t.x true;;

(Corrected the example)

Is it really necessary to fix this in 3.12 too ?

(0008261)
ygrek (reporter)
2012-10-16 10:45

ftr, example obviously meant
let t = { x = fun (type r) -> id' id };;
(0008264)
lealanko (reporter)
2012-10-16 12:09

Ah, right, the value restriction. I've been doing too much Haskell, already forgot about it. :) This poses a bit of a problem for me, but that's the price of imperative features. Sorry about the false alert.

- Issue History
Date Modified Username Field Change
2012-10-15 15:13 lealanko New Issue
2012-10-16 10:39 garrigue Note Added: 0008260
2012-10-16 10:39 garrigue Status new => resolved
2012-10-16 10:39 garrigue Fixed in Version => 4.00.0
2012-10-16 10:39 garrigue Resolution open => fixed
2012-10-16 10:39 garrigue Assigned To => garrigue
2012-10-16 10:45 ygrek Note Added: 0008261
2012-10-16 10:56 garrigue Note Edited: 0008260 View Revisions
2012-10-16 12:09 lealanko Note Added: 0008264


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker