1 / 24

Objects for Amadeus

Objects for Amadeus. Gert Smolka Programming Systems Lab, UdS, Saarbrücken August 1999. 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.

kalea
Download Presentation

Objects for Amadeus

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 for Amadeus Gert Smolka Programming Systems Lab, UdS, Saarbrücken August 1999

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

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

  4. Types as Interfaces int -> int • Function types do not fix implementation • Abstract types do • Object types strengthen types-as-interfaces property • record expressivity • subtyping (can forget fields) • partial type abstraction • higher-order polymorphism

  5. Object Type for Stacks type intStack = < put : int -> unit; get : int; empty : bool >

  6. Parameterisation type'a stack = < put : 'a -> unit; get : 'a; empty : bool >

  7. Recursion type 'a stack = < put : 'a -> unit; get : 'a; empty : bool; clone : 'a stack >

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

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

  10. Partial Type Abstraction sig type'a stack :> < put : 'a -> unit; get : 'a; empty : bool > val stack : unit -> 'a stack end • Generative • Can reveal abstract supertypes

  11. Subtype Ordering width depth Nonprimitive type constructors are invariant

  12. Type Inference • Derives omitted type annotations and type checks • Type weakenings must be annotated: exp • Constraints for method selections and type weakenings are delayed until enough information is available • Conservative extension of ML-style type inference • Clever use of type abbreviations

  13. Object-oriented Modelling versus ADTs • concise: e#me' rather than S.mee' • higher-order • interfaces are types rather than signatures

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

  15. Object Creation object(self) methodm = exp ... end • Objects have generative equality • Method declarations define pre-methods fnself=>exp that are applied to object upon method selection • self provides recursion

  16. Class Declarations class claid = fn pat => object(self) inheritance declarations field declarations method declarations initializers end new claid

  17. Class Declarations • Needed for inheritance • Methods can be overriden (with subtype) • self only visible in method declarations and initializers • Classes have status similar to structures • Class specifications for signatures • Protected methods are straightforward • Private methods are semantically non-obvious • Class identifier is automatically overloaded as type identifier for the respective object type

  18. Field Declarations • Analogous to value declarations of core language • Do not see self • Do not contribute to object type (i.e, fields are protected) • Are inherited • Are not overriden • Private fields • Mutable fields (important for cloning)

  19. Super inheritclassidexpassuper • super#m can be used in method declarations and initializers

  20. Cloning class c = object val mutable x = 0 method inc = x<-1 method clone = {< >} end

  21. class point1 = object val x = 0 method movex d = {< x = x+d >} end class('a) val x : int; method movex : int -> 'a end class point2 = object inherit point1 val y = 0 method movey d = {< y = y+d >} end class('a) val x : int; val y : int; method movex : int -> 'a; method movey : int -> 'a end Self Types in Class Interfaces

  22. Differences to Objective Caml • No partial type abstraction • Open object types • Fields as instance variables • Functional objects • Abstract classes and methods

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

  24. Binary Methods Expose Internals sig type t type point = < move : real * real -> unit; distance : point -> real; rep : t > val new : real * real -> point end • Alternative: partial type abstraction

More Related