Skip to content

Bounds on Types #49

@Victorious3

Description

@Victorious3

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 &.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions