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

[typing bug?] optional arguments and polymorphism #8403

Closed
vicuna opened this issue Dec 8, 2003 · 1 comment
Closed

[typing bug?] optional arguments and polymorphism #8403

vicuna opened this issue Dec 8, 2003 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 8, 2003

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

Bug description

Full_Name: Damien Pous
Version: 3.07+6 (2003-11-25)
OS: Debian/GNU Linux
Submission from: mailhost.ens-lsh.fr (193.51.131.2)

Using polymorphic variants, the following function `k' is given a polymorphic
type :

let a = function `A -> 5 | _ -> 0;;

let k ?(g = a) () = g `A;;

val k : ?g:([> `A ] -> int) -> unit -> int =

let b = function A -> 6 | B -> 7 | _ -> 0;;

let _ = k ~g:b ();;

  • : int = 6

But not when doing the same thing with objects :

let a = object method a = 5 end;;

let k ?(g = a) () = g#a;;

val k : ?g:< a : int > -> unit -> int =

let b = object method a = 6 method b = 7 end;;

let _ = k ~g:b ();;

This expression has type < a : int; b : int > but is here used with type < a :
int >

(that's the same using classes)

@vicuna
Copy link
Author

vicuna commented Dec 8, 2003

Comment author: administrator

From: Damien.Pous@ens-lyon.fr

But not when doing the same thing with objects :

let a = object method a = 5 end;;

let k ?(g = a) () = g#a;;

val k : ?g:< a : int > -> unit -> int =

What about

let k ?g () = match g with None -> a#a | Some g -> g#a;;

val k : ?g:< a : int; .. > -> unit -> int =

or

let k ?g () =

let g = match g with None -> a | Some g -> (g :> <a:int>) in g#a;;

val k : ?g:< a : int; .. > -> unit -> int =

Objects and variants are different, you cannot expect them to behave
identically.

Jacques

@vicuna vicuna closed this as completed Dec 8, 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