I want to add a my personal list of desired features. I don’t restrict to 1.0, maybe some are 2.0+.
Most ideas were evoked by the arguments in discourse #5278 and the links therein.
-
Type system
Keep the type system simple and elegant as it is now. Types and inheritance should remain the only relevant inputs for method dispatching.
- Abstract types (stateless, no instances) and concrete types (structs) (optionally statefull, instanciable) shall be the only “type-like” constructs of the language. Other related features (known as traits, interfaces, protocols,…) could be added as optional properties to the types. I will go into details later.
- Allow method signatures. That could be parametric subtypes of
Function
. e.g.Function{Int, AbstractVector{T}} where T...
. Used for dispatching:function f(g::Function{Int}) ...
. The signature does (not) include function name? -
Interfaces/protocols
Optionally add method signatures as members ofabstract type
andstruct
.
Syntax e.g.struct S ... fname::Function{Int} end
.
Semantics: check after end of compilation the existence of specified methods.
Warnings, if missing methods (signature including name). -
Abstract multiple inheritance.
Syntax e.g.struct N <:A<:B ...
orabstract type N <:A::B::C
… whereA,B,C
are already defined types.
Semantics: For the purpose of dispatching replace chain of supertypes by linearized list of set of all supertypes. This concept is stolen fromScala
, see also here: linearization. - Allow singular inheritance from concrete types. That means, new concrete types can be defined by extending existing concrete types, if they do not add own state.
Syntax e.g.:struct N <:S[<:A...] < end
whereS
is has state,N
has no own data fields,A
additional abstract.
Semantics: The new type shares state and layout with the old one (methods of course). Implicitly define default conversion functionN(::S)
.
Example:struct RichString <: String; blow_up::Function{RichString} end
. Conversion:RichString("abc")
. - Implement implicit conversions. In the case of concrete inheritance (5.), in a restricted context treat all objects
x::S
asN(x)
. That would, together with (5.), cover an essential property of traits. discourse
Example:blow_up("def")
- Implement automatic delegation to methods of data members.
Syntax e.g.struct S ...; delegate data::T ... end
.
Semantics: add all methods of T (known by interface definitions in T) to the method list of S and use them at runtime. Resolve conflicts by defining breadth/depth-first search. This contributes also this old problem: type mixin #816
-
Type stability
Improve support for type stabilty.
- make the
{Core.Inference|Base}.return_type[s]
methods first class (documented, inBase
). - make the output more exact. For example
return_type(cmp, (Real, Real))
should beInt64
and notAny
.
to be continued