[Grace-core] Extending types (Was Re: Type syntax)

Kim Bruce kim at cs.pomona.edu
Fri Feb 7 17:27:05 PST 2014


Thanks for the clarification.  I agree with your solution to the unbound E.  Interestingly, the return type issue with Indexable Collection really only appears with immutable collections, as the Collection type doesn't show up in the return type of methods if the collections are mutable (unless you decide to throw in a clone type operation).

Of course, we do want to support immutable collections, so don't want to ignore this.  It is the case that handling of SelfType is easy if it appears in positive positions (like return types), so that would be a relatively simple addition.  It will, however, get more complex if SelfType can appear in negative positions (like parameter types).

As I believe Michael would likely argue, this is a matter of choosing the right pluggable type system (and hence dialect) for use in this circumstance.  We will need to address this at some point, but I would urge us to get the basics designed and implemented and then decide how to support the richer SelfType.  For now we could use the (ugly) solution like that in Java, where we use matching to get the right type.  (The MyType solution in my book would work fine if we decide to implement it later.) 

Kim



On Feb 7, 2014, at 4:50 PM, Andrew P. Black <apblack at ownmail.net> wrote:

> 
> On 7 Feb 2014, at 14:00, Kim Bruce <kim at cs.pomona.edu> wrote:
> 
>> What is the definition of Collection in your example?  Your definition in collections.grace in GUnit looks different:
>> 
> 
> Let’s assume something like
> 
> 	type Collection<E>  = { add(element: E) -> Collection<E>; remove(element: E) -> Collection<E>; … }
> 
> I was seeing two issues.  One is insisting that the type parameters are uniform:
> 
> 	type IndexableCollection = Collection<E> & type { at(ix:Number) -> E; at(ix:Number) put(e:E) }
> 
> clearly doesn’t work, because the E is unbound, but on reflection, I think that 
> 
> 	type IndexableCollection<E> = Collection<E> & type { at(ix:Number) -> E; at(ix:Number) put(e:E) }
> 
> would work OK.  
> 
> The other is that the operations in IndexableCollection need to return an IndexableCollection, not a Collection.  That’s what I was meaning by SelfType.  We have to “tie the fixpoint knot”  after we have done the &, not before, to get the right type.  
> 
> 	Andrew
> 
> _______________________________________________
> Grace-core mailing list
> Grace-core at cecs.pdx.edu
> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core

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


More information about the Grace-core mailing list