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
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;;
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.
Original bug ID: 5790
Reporter: lealanko
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-07-24T08:39:03Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.00.1
Fixed in version: 4.00.0
Category: typing
Monitored by: @hcarty
Bug description
Previously, 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:
type t = { x : 'r . 'r -> 'r };;
type t = { x : 'a. 'a -> 'a; }
let id x = x;;
val id : 'a -> 'a =
{ 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 };;
However, in 4.00 this no longer works:
type t = { x : 'a . 'a -> 'a };;
type t = { x : 'a. 'a -> 'a; }
let id x = x;;
val id : 'a -> 'a =
{ 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 reproduce
type t = { x : 'r . 'r -> 'r }
let id x = x
let _ = { x = fun (type r) -> id id }
The text was updated successfully, but these errors were encountered: