Skip to content

Allow specifying generic types at callsite? #887

Description

@timbertson

Currently a function definition can specify generic types, e.g. fun foo<a>(value: a). In other languages the concrete types for these generics can be specified at the callsite, e.g. foo<int>(1). I would like koka to support this too.

I find myself wanting this feature when dealing with type errors, nailing down some specific parts allows me to better narrow down where the problem is. Along with #695, these seem like common features to eliminate places where type inference causes a confusing error message which could be improved if the programmer can lock down some of the type constraints.

It would be good to allow a partial specification, e.g. foo<a,_>(...) for a function with multiple generic types.

Given that implicit generics (i.e. single-letter with an optional number) are so frequently used, this would need to be supported too. The obvious option is to order the params according to their first appearance. e.g. foo(val1: a, val2: b, val3: () -> e c) would be equivalent to foo<a,b,e,c>(...). (maybe this is already how it works internally?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions