typed_python icon indicating copy to clipboard operation
typed_python copied to clipboard

Function type signatures should allow more sophisticated matching criteria

Open braxtonmckee opened this issue 5 years ago • 0 comments

Right now we can write

def f(x: int, y: int):
    ...

but we have no way of describing the idea that we want 'f' with two arguments that are the same, or some other more complex match.

One way to do this would be to allow an arbitrary python function to run to check the arguments. Another option would be to develop a grammar of "types" that can be passed to the Function signature to allow it to choose how it specializes. For instance, imagine we have an object called template. Then we could have

def f(x: template.X, y: template.X):
   ...

where the semantics are that we match arguments from left to right and when a template variable is encountered, its value is set and future versions of that pattern insist that the value matches. this could let you say things like f(x: Dict(int, template.X), y: Dict(template.X, str)) to insist that the two types covary in a meaningful way.

braxtonmckee avatar Jun 30 '19 03:06 braxtonmckee