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: 1976 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
let a = fun x -> x = [] in
let b = ref a in
b := (fun x -> x = [1.0]);
b := a;
ignore (a [1]);
ignore (!b [1])
compile:
ocamlc f.ml
File "f.ml", line 6, characters 12-13:
This expression has type int but is here used with type float
======================
This is the normal and well known behaviour of Caml polymorphism.
Identifier b has never been defined as a polymorphic value, due to its
definition as a function application. Also, after the first assigment
to b, the type of b is entirely monomorphic and hence cannot be used
both with float lists and int lists.
The following toplevel session may enlight the type assignments that
occur in your example :
let a = fun x -> x = [];;
val a : 'a list -> bool =
let b = ref a;;
val b : ('_a list -> bool) ref = {contents = }
b := (fun x -> x = [1.0]);;
: unit = ()
b;;
: (float list -> bool) ref = {contents = }
From here !b can be applied to float lists and to float lists only.
The next assignment does not change the types neither b's nor a's:
Original bug ID: 1976
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Mikhail Zabelin
Version: OCaml 3.07pl2 native Win32 port (MinGW)
OS: Win2000
Submission from: www-proxy.ioffe.rssi.ru (194.85.224.35)
source file f.ml:
let a = fun x -> x = [] in
let b = ref a in
b := (fun x -> x = [1.0]);
b := a;
ignore (a [1]);
ignore (!b [1])
compile:
The text was updated successfully, but these errors were encountered: