Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected typing #8412

Closed
vicuna opened this issue Dec 15, 2003 · 2 comments
Closed

Unexpected typing #8412

vicuna opened this issue Dec 15, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 15, 2003

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:

ocamlc f.ml
File "f.ml", line 6, characters 12-13:
This expression has type int but is here used with type float
======================

@vicuna
Copy link
Author

vicuna commented Dec 15, 2003

Comment author: administrator

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:

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:

b := a;;

  • : unit = ()

b;;

  • : (float list -> bool) ref = {contents = }

a;;

  • : 'a list -> bool =

Hence the error reported by the typechecker.

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/

@vicuna
Copy link
Author

vicuna commented Dec 20, 2003

Comment author: administrator

Normal behavior (monomorphic refs).

@vicuna vicuna closed this as completed Dec 20, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant