You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently its only possible to constrain a type using this syntax:
def my_fun(a: type &T, b: type [T])
which works fine if your constraints are as simple as "I take any array" or "I take any reference"
Interfaces can be used directly to create a constraint on a type:
type Interface = interface { def fun }
def my_fun(a: Interface) {
a.fun()
}
However, this breaks down as soon as you want multiple arguments using the same concrete type.
It is also a bit confusing to not being able to assign two different arguments using Interface because they might be completely different types.
The new syntax for creating bounds would look like this:
def my_fun(a: type T > [T], b: type U > Interface, c: U)
This can completely replace the old "Pattern style" syntax.
Another upside of this is being able to use union types for arguments and have them be compile time:
def my_fun(a: type T > int | double | float)
This would create a polymorphic function that takes either an int, double or float.
You can also combine multiple constraints:
def my_fun(a: type T > Interface & Interface2)
This would mainly be handled by being able to concat interfaces together using &.
The text was updated successfully, but these errors were encountered:
Currently its only possible to constrain a type using this syntax:
which works fine if your constraints are as simple as "I take any array" or "I take any reference"
Interfaces can be used directly to create a constraint on a type:
However, this breaks down as soon as you want multiple arguments using the same concrete type.
It is also a bit confusing to not being able to assign two different arguments using
Interface
because they might be completely different types.The new syntax for creating bounds would look like this:
This can completely replace the old "Pattern style" syntax.
Another upside of this is being able to use union types for arguments and have them be compile time:
This would create a polymorphic function that takes either an int, double or float.
You can also combine multiple constraints:
This would mainly be handled by being able to concat interfaces together using
&
.The text was updated successfully, but these errors were encountered: