magic-lang / rock

ooc compiler written in ooc
http://ooc-lang.org/
MIT License
14 stars 4 forks source link

[Feature] Generic (interface) constraints #64

Open alexnask opened 8 years ago

alexnask commented 8 years ago

I vaguely remember this exact issue being discussed in some ooc-lang/rock issue but I am basically talking about this kind of stuff:


Comparable: interface {
    greater?: func(other: This) -> Bool
    lesser?: func(other: This) -> Bool
}

f: func <T: Comparable> (a, b: T, g: Func) {
    if (a greater?(b)) {
        g()
    }
}

Basically, the above would be equivalent to:


f: func (a, b: Comparable, g: Func) {
    if (a greater?(b)) {
        g()
    }
}

But make sure that a, b are of the same type (or have a common root type).

marcusnaslund commented 8 years ago

Do you mean this one? https://github.com/ooc-lang/rock/issues/822

alexnask commented 8 years ago

@marcusnaslund

Oops, I thought it was just a tangent discussion on a closed issue.
This is indeed the issue I was referring to.

alexnask commented 8 years ago

My knowledge on the way interfaces are implemented in the runtime is probably the shakiest out of all ooc features.

I will be looking into it in more depth and fixing as many bugs as possible and possibly implementing this (although this would probably be a part of the much needed typearg system rewrite).