[Grace-core] Inconsistent declaration syntax

Kim Bruce kim at cs.pomona.edu
Sun Aug 5 20:52:09 PDT 2012


I suspect that I am the one who originally argued for the use of a different keyword for type definitions.  Certainly,
	type T = {...}
and
	def T = type{...}

are both plausible syntaxes for type definitions.   I liked having a different keyword because the syntax of the right hand sides are quite different.   On the other hand if we wish to be able to use "anonymous" types, then a syntax like the second is reasonable.  Do we want to allow
	method m(x: type{m:...,n:...},...) {...}

If so, then that is a plausible notation.  After all we do the same thing for objects with the result that anonymous objects can be used in expressions.  (By way of contrast, Scala uses declarations for objects, rather than generative expressions.)

I believe right now the only type expressions we can use in other expressions use the type operations (intersection, union, etc.).  If we keep that restriction it seems somewhat annoying to require two keywords (def and type) in a type definition.  On the other hand, using separate starting keywords (def and type) makes it somewhat easier to see at a glance which definitions are values and which are types (and as James points out, we generally don't want to use types in other expressions).

I don't feel really, really strongly about this, but nobody has seemed to have difficulty with this syntax so far, so I'm inclined to leave it alone unless we want anonymous type definitions.

Kim



On Aug 5, 2012, at 6:07 PM, James Noble wrote:

>> I certainly agree that a type used as an annotation on a variable or method must be manifest if we want "static" type checking.   Attempting to use a type like WeirdType for such a purpose would certainly generate an error from the static type checker.  
> 
> indeed  - and that would be the other way to do it - 
> pinging the use, not definition of such a type. 
> 
>> But I was asking a different question:  why require a different syntax for the declarations?
> 
> so what are the options?  Is this what you're getting at?
> (eliding the := vs = redundancy on vars & defs) 
> 
> *consistent syntax with just ="
> 
> def name = expression
> var name = expression 
> method name(params) name(params) = {body}
> type name = type_expression  
> class name = {body} 
> 
> object { body } clearly doesn't fit in here
> 
> *consistent syntax without ="
> 
> def name expression
> var name expression
> type name expression 
> method name(params) name(params) {body}
> type name = type_expression
> class name {body}
> 
> James
> _______________________________________________
> Grace-core mailing list
> Grace-core at cecs.pdx.edu
> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core



More information about the Grace-core mailing list