[Grace-core] Extending types (Was Re: Type syntax)
Andrew P. Black
apblack at ownmail.net
Fri Feb 7 16:50:17 PST 2014
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140207/d4850f2c/attachment-0001.html>
More information about the Grace-core
mailing list