ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
401 stars 40 forks source link

Allow implementing interfaces after type declaration #995

Open alexnask opened 8 years ago

alexnask commented 8 years ago

Proposed syntax:


Fooable: interface <T> {
    foo: func -> T
}

// Perhaps 'extend Cell<T> implements Fooable<T>'
extend Cell<T> as Fooable<T> {
    foo: func -> T {
        val
    }
}

@fasterthanlime Thoughts?

alexnask commented 8 years ago

Potential issues:
What happens if the type already implements the interface but hasn't been declared that way?

For example:


Printable: interface {
    toString: func -> String

    print: func {
        toString() println()
    }
}

extend Int as Printable {
    // 'toString: func -> String' already exists in the original Int declaration
    // Should it be automatically detected?
    // Obviously, you cannot re-declare it.
}

Edit: In my opinion, interface required functions not implemented in the addon should be looked up in the type declarations and used automatically.