Replies: 1 comment
-
|
Now done! #995 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@typing.overloadallows to describe a number of variants of the same function with different type signatures - but the same actual function body.We could add
@guppy.overloadwhich allows a number of variants of a function with different type signatures, and different function bodies.For example, consider the
rangefunction which has three variants (taking 1, 2 or 3 ints - note, these are not easily satisfied by "default arguments" as the one-argument version provides a value only for the second parameter, with the first parameter defaulting), this could be expressed as follows:Each call would be statically resolved by static argument type. We shouldn't need to worry about overlap between cases because guppy has no classes/subtyping (so we should probably require all variants to have identical return type, too - at least until we implement
Union).Hence, this provides a different way to handle functions which would otherwise need
Unionarguments (at the cost of providing separate code for each).We could also then extend the frontend (only) to provide python-like default arguments backing onto this, i.e. without any further backend changes, although default arguments probably merits a discussion of its own (e.g. perhaps we require the values to be immutable, ruling out one of the top/worst python "gotchas")...
However, it might prove too much of a stopgap measure, i.e. it seems of limited use when we do have
Unioncompiling to Hugr Sum type.Beta Was this translation helpful? Give feedback.
All reactions