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

Warning: this expression should have type unit #2650

Closed
vicuna opened this issue Jan 5, 2001 · 1 comment
Closed

Warning: this expression should have type unit #2650

vicuna opened this issue Jan 5, 2001 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Jan 5, 2001

Original bug ID: 256
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Damir Jamsek
Version: Ocaml 3.00
OS: Linux
Submission from: ss08.nc.us.ibm.com (32.97.136.238)

If you compile the following lines, the warning message only occurs for
the sequential composition in function foo, but not in function bar

comments?
thank you,
--damir

(* file: foobar.ml; Compile: ocamlc -c foobar.ml *)

let foo_tbl = ((Hashtbl.create 1013) : (int,int) Hashtbl.t)
let bar_tbl = Hashtbl.create 1013

let foo f = Hashtbl.find foo_tbl f; failwith "foo"
let bar b = Hashtbl.find bar_tbl b; failwith "bar"

(* function doo helps typing bar_tbl *)
let doo d = d + Hashtbl.find bar_tbl d

@vicuna vicuna closed this as completed Jan 8, 2001
@vicuna
Copy link
Author

vicuna commented Jan 8, 2001

Comment author: administrator

Full_Name: Damir Jamsek
Version: Ocaml 3.00
OS: Linux
Submission from: ss08.nc.us.ibm.com (32.97.136.238)

If you compile the following lines, the warning message only occurs for
the sequential composition in function foo, but not in function bar

comments?
thank you,
--damir

(* file: foobar.ml; Compile: ocamlc -c foobar.ml *)

let foo_tbl = ((Hashtbl.create 1013) : (int,int) Hashtbl.t)
let bar_tbl = Hashtbl.create 1013

let foo f = Hashtbl.find foo_tbl f; failwith "foo"
let bar b = Hashtbl.find bar_tbl b; failwith "bar"

(* function doo helps typing bar_tbl *)
let doo d = d + Hashtbl.find bar_tbl d

The sequence warning is an approximation: when examining e1; e2, if
the compiler can prove that the type of the expression e1 cannot be
unit, it emits a warning. For instance, when defining foo the compiler
knows that Hashtbl.find would return an integer (due to the
explicitely declared type of foo_tbl), hence the warning. By contrast,
when defining bar the type instance of bar_tbl is still unknown and
thus the result type of the expression Hashtbl.find bar_tbl b is an
unknown type variable which could eventually be unified with unit
afterwards, hence the type checker cannot prove that this type cannot
be unit and it does not emit the sequence warning.

Best regards,

Pierre Weis

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

@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