[Grace-core] RFC: Compile-time constants

Andrew P Black andrew.p.black at gmail.com
Fri May 2 17:58:38 PDT 2014


On 1 May 2014, at 22:55 , Timothy Jones <tim at ecs.vuw.ac.nz> wrote:

> let MyType<T> = type { thing -> T }
> 
>  let aThing = brand
> 
>  let Thing = aThing.pattern & type { another -> MyType<Thing> }
> 
>  def myThing : Thing = object is aThing {
>    def another is public = object { def thing is public = outer }
>  }
> 
> The static behaviour of this example should be clear,

Not at all.  You don't say what your goal is: what are you trying to achieve?

> but all of the
> declarations contain real objects

Yes

> which must be created at runtime.

No.  Your premise is that you know everything about these objects at compile time.   So get "unstuck" from the idea that objects don't exist until runtime.   Objects like 1 and true exist at compile time; so do type objects.   In fact, you can regard any immutable object that can be written in the program as existing at compile time.

Of course,  semantically,  there is no phase distinction (between compile- and run-time) in the language.  Pragmatically, the compiler can lay down the object structure at compile time; it doesn't have to lay down code and then ensure that this code is executed at runtime to produce the object later.

> So, the
> right-hand side of a

manifest?

> declaration must be 'statically known': either a type
> literal, a generic parameter, the dialect, or a request for a let declaration or
> a method that is annotated as static (either in scope or on another statically
> known value).

Generics are just manifest methods — methods that can be evaluated at compile time, because they are (1) guaranteed to terminate, and (2) have manifest arguments.

> Andrew mentioned that he would like statically known
> declarations for traits, so I would like to know more about that use case.

I'll try and come up with a nice example for you.  But the basic idea is to get rid of the kludge where the inherited object must be "definitively static" and to use the same manifest mechanism that you are proposing there.   An object can use (rather than inherit) a manifest object that contains only methods — which is exactly what a trait is.    The difficulty in Grace is that methods can capture non-local variables, and use methods of the dialect.  

	Andrew




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140502/460941fb/attachment.html>


More information about the Grace-core mailing list