Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001967OCamlOCaml generalpublic2003-12-08 10:262003-12-08 20:40
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001967: [typing bug?] optional arguments and polymorphism
DescriptionFull_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 = <fun>

# 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 = <fun>

# 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)

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0002762)
administrator (administrator)
2003-12-08 18:44

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 = <fun>

What about

# let k ?g () = match g with None -> a#a | Some g -> g#a;;
val k : ?g:< a : int; .. > -> unit -> int = <fun>

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 = <fun>

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

Jacques


- Issue History
Date Modified Username Field Change
2005-11-18 10:14 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker