[RFC] Implement type inheritance #142
Labels
feature-request
Any request for a new feature of the language. Includes both syntax and library features.
rfc
A request for comments from the community
semantics.interpreter
Any issue relating to changing the semantics of interpreter code.
semantics
Generic label for semantics issues. All semantics issues should have this tag.
syntax
Any issue relating to the syntax of Myst.
Milestone
While talking about how to re-implement
IO
as a type rather than a module, it seemed to make the most sense to have IO be a supertype that other types can inherit from. For example, aSocket
is anIO
and aFileDescriptor
is anIO
. With the original idea of using module composition, the semantics would be more thatSocket
is a type that acts like anIO
.Assuming that inheritance is added to the language, the question then becomes how it should be represented in the syntax. I see two decent options for how this could work:
<
operator as a keyword::
:I like the second option more, because it fits nicely with the existing syntax for type restrictions on method parameters.
The other consideration is how this will work in the interpreter itself. The simplest solution seems to be adding another property,
supertype
, toTType
. Then,TType#ancestors
will call#ancestors
on the supertype and append the result to the list it already created.Since Myst doesn't support singleton classes or other metaprogramming concepts like Ruby/Crystal does, I think this implementation will be sufficient for most cases.
The text was updated successfully, but these errors were encountered: