1 / 15

Objects in Objective Caml

Objects in Objective Caml. Gert Smolka Programming Systems Lab, UdS, Saarbrücken August 1999. Motivation. Starting or reference point for objects in Amadeus Represents a decade of research in FP + OO Mitchell Wand, LICS 1987 Didier Rémy, POPL 1989

iolana
Download Presentation

Objects in Objective Caml

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Objects in Objective Caml Gert Smolka Programming Systems Lab, UdS, Saarbrücken August 1999

  2. Motivation • Starting or reference point for objects in Amadeus • Represents a decade of research in FP + OO • Mitchell Wand, LICS 1987 • Didier Rémy, POPL 1989 • Competing designs: MOBY and ML2000, based on implicit subtyping

  3. Sources • User's Manual, OCaml Release 2.02 (March 1999) • Objective ML: An effective object-oriented extension to ML, D. Rémy and Jérôme Vouillon. Theory and Practice of Object Systems,(4)1:27-50,1998. • Principles and a Preliminary Design for ML2000, ML2000 Working Group, March 1999 • The Design of a Class Mechanism for MOBY, Kathleen Fischer and John Reppy. POPL 1999.

  4. External View Use of Objects Object Types Internal View Creation of Objects

  5. Object Type for Stacks type 'a stack = < put : 'a -> unit; get : 'a; empty : bool; clone : 'a stack >

  6. Object Types • List method names with their types • Methods are obtained from pre-methods fn self => expression upon method selection o#m as in sigma calculus of Abadi & Cardelli • Can be recursive • No polymorphic methods

  7. type 'a stack = < put : 'a -> unit; get : 'a; empty : bool; clone : 'a stack > type 'a queue = < put : 'a -> unit; get : 'a; empty : bool; clone : 'a queue > Object Types have Structural Equality • Definitions of object types are non-generative • Type constructors stack and queue are equal • Cannot separate stacks from queues

  8. Subtype Ordering width depth Nonprimitive type constructors are invariant

  9. Explicit Subtyping with Coercions (exp :> typ) • No coercions to subtypes (would require types at run-time, non-obvious for functions) • Signature matching does not incorporate subtyping

  10. Open Object Types <M1 ... Mn;..> • Can express most general type of method selection #m <m:'a;..> -> 'a • Can express most general type of cloning function (<..> as 'a) -> 'a • Can express general type of min function (<m:int;..> as 'a) * 'a -> 'a • Subtype ordering defined as one would expect

  11. Type Inference • Method selection: No problem due to open object types • Coercions: Heuristic, can be avoided with (exp : t :> t') • Attractive alternative for Amadeus: • Write exp for coercions • Infer lower and upper type and verify subsumption • Clever use of type abbreviations

  12. Binary Methods Expose Internals sig type t type point = < move : real * real -> unit distance : point -> real rep : t > val new : real * real -> point end

  13. Fixed by Partial Type Revelation sig type point :> < move : real * real -> unit distance : point -> real > val new : real * real -> point end

  14. Lack of Polymorphic Methods type 'a stack = < put : 'a -> unit; get : 'a; empty : bool; map : ['b] ('a -> 'b) -> 'b stack >

  15. Advantages of Object types over ADTs • Less to write: e#me'rather than S.m(e,e') • Object types can be declared independent of their implementations,implementations can be added as needed • More polymorphism: • Coercions (explicit subtype polymorphism) • Open object types (row polymorphism)

More Related