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

Incompatible class method's types #3603

Closed
vicuna opened this issue Apr 20, 2005 · 1 comment
Closed

Incompatible class method's types #3603

vicuna opened this issue Apr 20, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Apr 20, 2005

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:

  1. 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

  1. 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 =

  1. get an object of the first kind:
    let instance = new with_option ();;

val instance : with_option =

  1. 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.

@vicuna
Copy link
Author

vicuna commented Jul 12, 2005

Comment author: administrator

Full_Name: Snark on #ocaml

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.

Jacques

@vicuna vicuna closed this as completed Jul 12, 2005
@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