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: 3603 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
define a class that can provide me a message (with optional choice!):
class with_option () =
object
method text ?option () =
match
option
with
None -> "Hello, world!\n"
| Some str -> "Hello, " ^ str ^ "!\n"
end;;
class with_option :
unit -> object method text : ?option:string -> unit -> string end
define some function that uses such an object (without the optional
choice!):
let printer obj = print_string (obj#text ());;
val printer : < text : unit -> string; .. > -> unit =
get an object of the first kind:
let instance = new with_option ();;
val instance : with_option =
try to use it:
printer instance;;
This expression has type with_option but is here used with type
< text : unit -> string; .. >
Types for method text are incompatible
Why do I think it is a bug? The prototypes are different after all!
Well, the printer function's prototype doesn't mean "I want an object that does
exactly the following", it means "I want an object that does at least the
following". The prototypes are different, but compatible.
I can make my program work by explicitly giving the type of obj when defining
printer, but that is dirty.
I hope this report helps.
The text was updated successfully, but these errors were encountered:
val printer : < text : unit -> string; .. > -> unit =
printer instance;;
This expression has type with_option but is here used with type
< text : unit -> string; .. >
Types for method text are incompatible
This problem is explained in the manual. See section 4.1.2.
The efficient compilation method used for optional arguments requires to give
the type information in advance.
Original bug ID: 3603
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Snark on #ocaml
Version: 3.08.3
OS: debian unstable
Submission from: lns-vlq-36-gre-82-253-91-52.adsl.proxad.net (82.253.91.52)
A minimal example first:
class with_option () =
object
method text ?option () =
match
option
with
None -> "Hello, world!\n"
| Some str -> "Hello, " ^ str ^ "!\n"
end;;
class with_option :
unit -> object method text : ?option:string -> unit -> string end
choice!):
let printer obj = print_string (obj#text ());;
val printer : < text : unit -> string; .. > -> unit =
let instance = new with_option ();;
val instance : with_option =
printer instance;;
This expression has type with_option but is here used with type
< text : unit -> string; .. >
Types for method text are incompatible
Why do I think it is a bug? The prototypes are different after all!
Well, the printer function's prototype doesn't mean "I want an object that does
exactly the following", it means "I want an object that does at least the
following". The prototypes are different, but compatible.
I can make my program work by explicitly giving the type of obj when defining
printer, but that is dirty.
I hope this report helps.
The text was updated successfully, but these errors were encountered: