[Grace-core] Fwd: Some notes on pattern matching on the wiki

James Noble kjx at ecs.vuw.ac.nz
Mon Jul 11 03:59:52 PDT 2011


So let's talk about modules!

> I want modules to package up:
>    a collection of objects and classes
>    a collection of types

absolutely...

> It should indicate which of these items should be exported and also indicate what items from other modules should be imported.  I had hoped that they could also indicate a subset of the method names in an object type to be exported, but I am willing to give that up.

I think that would be possible - but it may require extra dynamic checks - 
at least if you're executing via type dynamic. 

> It would be nice to support renaming (of types and/or method names) in some way, but that is less crucial for a language for novices.

should be do-able, though, at least for types

> Ideally we would have separately compiled module specifications and implementations (the specification just lists declarations and any contracts/comments, but with no operational semantics).

sure. though I think you mean no operational code...

There is some earlier discussion of modules here: https://projects.cecs.pdx.edu:8443/~black/NewOOL/index.cgi/wiki/ModulesPage

and I've copied Ewan & Kims messages to near that in the wiki.

- - - 

OK so here's a first cut at a module syntax addressing most of those things - Modular-3 style - 
based on Kim's module syntax from that WIki page

> specification module ShapeLibrary {     // name
> 
> import Graphics      // external dependencies
> 
> from Graphics import Point
> from Graphics import Rectangle as GRectangle 
> 
> public type Shape {
>   draw(GraphicsContext)
>   bounds -> Rectangle
> }
> 
> // it seems really odd *not* to "export" these! 
> public type Rectangle extends Shape {} 
> public type Circle extends Shape {}
> 
> // I had to make up names for these two
> public type RectangleFactory { new(GRectangle) -> Shape }
> public type CircleFactory { new(Point) -> Circle }
> }
> 
> 
> module ShapeImplementation 
>  implmenents Shapelibrary {
> 
> //assuming implementation module automagically imports 
> // everything the spec module implements
> 
> import Collections 
> from Collections import List
> 
> // assume class X creates a type X of all non-private methods, 
> // and a factory called XFactory
> 
> public class Rectangle { 
>     rect' : GRectangle ->
>  const rect := rect'
>  method draw(gc : GraphicsContext) { gc.draw(rr) } 
>  const bounds := rect'
> }
> 
> public class Circle {
>  centre' : Point -> 
>  const centre := centre'
> }
> 
> } // end module


And, the same thing in done Gilad- style, in Grace:

> 
> class ShapeLibrary {  
>  gfx : Graphics -> 
> 
> const Point := gfx.Point
> const GRectangle := gfx.Rectangle
> 
> public type Shape {
>   draw(GraphicsContext)
>   bounds -> Rectangle
> }
> 
> public type Rectangle extends Shape {} 
> public type Circle extends Shape {}
> 
> public type RectangleFactory { new(GRectangle) -> Shape }
> public type CircleFactory { new(Point) -> Circle } 
> }
> 
> 
> 
> class ShapeImplementation 
>  extends Shapelibrary.new(gfx) {
>  gfx : Graphics, col : Collections ->
> 
> const List := Collections.List
> 
> public class Rectangle 
>   implements super.Rectangle { 
>     rect' : GRectangle ->
>  const rect := rect'
>  method draw(gc : GraphicsContext) { gc.draw(rr) } 
>  const bounds := rect'
> }
> 
> public class Circle implements super.Circle {
>  centre' : Point -> 
>  const centre := centre'
> }
> 
> } // end module


More information about the Grace-core mailing list