1 / 14

Implementing Relationships in Whiley

Implementing Relationships in Whiley. David J. Pearce School of Engineering and Computer Science, Victoria University of Wellington, New Zealand Dagstuhl Seminar 10152. Computation. Data. Computation Versus Model. Composition. Delegation. Querying. Polymorphism. Pointers. Computation.

john
Download Presentation

Implementing Relationships in Whiley

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. ImplementingRelationships in Whiley David J. Pearce School of Engineering and Computer Science, Victoria University of Wellington, New Zealand Dagstuhl Seminar 10152

  2. Computation Data Computation Versus Model

  3. Composition Delegation Querying Polymorphism Pointers Computation Data Records Databases Datatypes Structuring Values Sets Computation Versus Model

  4. User Book Compiler Loader * 1 ID Name Code Title Compile(…) LoadClass(…) Behavioural Structural * 0..1 What about Relationships ?

  5. Structural Relationships • Can implement using pointers (as above) • Can implement using collections class User { private Set<Book> books; … } class Book { private User borrower; … }

  6. Behavioural Relationships compiler loader • Must be implemented using Pointers class Compiler { private ClassLoader loader; … } class ClassLoader { private Compiler compiler; … }

  7. Introducting Whiley !!! • Hybrid OO – Functional Language • Compiles to JVM • Performs Compile-Time Checking of Constraints

  8. Functional Core • Functional functions • No aliasing or side-effects • Pass-by-value records, lists + sets define int where$ >= 0as nat int f(nat a, nat b)ensures $ > 0: ifa == b: return 1 else: return a + b

  9. Imperative Outer Layer define process(int x, int y)as PointProc void PointProc::update(int z): this->y = z void System::main([string] args): PointProc pp = spawn (x:1,y:2) pp->update(3) print str(*pp) • Processes • Like objects, but stricter concurrency • Send and Receive Messages • Majority of work done with functions • Are necessary for I/O and … ?

  10. Borrows Relationship in Whiley define (int id, string name)asUser define (int code, string title)asBook define{(User user, Book book)}where no{ x in $, y in $, x.book==y.book && x!=y } as Borrows int count(user u, Borrows bs): return|{ x|x in bs, x.user==u }| • Structural relationships implemented in functional core • (No need to implement them elsewhere)

  11. Inheritance define int where$ >= 0asnat defineintwhere $ > 0 as pint defineintwhere $ < 10 as lten define nat where $ < 10 as bnat • Inheritance is implicit, not explicit • Multiple inheritance is no problem lten nat bnat pint

  12. Compiler-Loader in Whiley define(…)as JvmClass defineprocess(string path,…)as Compiler defineprocess(Compiler cmp,…)as Loader JvmClass Loader::loadClass(string name): … … returncmp->compile(filename)

  13. Another behavioural example • Delegator Pattern • Classic behavioural relationship • Implemented with processes in Whiley • Requires polymorphism … not implemented yet! FileReader BufferedReader StringReader

  14. whiley.org (under construction)

More Related