docs: Update functions chapter for v1#178
Conversation
| Here, we tried to assign either ``a_function`` or ``b_function`` to the variable ``f``, but the compiler tells us that these values have different types. | ||
| This is because the default type assigned to a function value statically tracks the corresponding definition it came from. | ||
| These are the ``def a_function(n: int) -> int`` and ``def b_function(n: int) -> int`` types that showed up in the error message above. | ||
| To fix this, we can follow the compiler's suggestion and annotate ``f`` with a ``Function`` type. |
There was a problem hiding this comment.
The compiler suggestion is implemented in Quantinuum/guppylang#2013 but not released yet, so doesn't show up in the current build :/
| def return_callable() -> Callable[[int], bool]: | ||
| return is_even | ||
|
|
||
| return_callable.check() |
There was a problem hiding this comment.
The current error message is very bad, see Quantinuum/guppylang#2027
There was a problem hiding this comment.
CalMacCQ
left a comment
There was a problem hiding this comment.
Looks good :) I'm a tad confused by the return_function and return_callable examples so I've asked for some clarification on that.
Only other suggestion is to cross-link to the API docs for Guppy Function and Callable.
| def return_callable() -> Callable[[int], bool]: | ||
| return is_even | ||
|
|
||
| return_callable.check() |
There was a problem hiding this comment.
| return f | ||
| def call_a_or_b(flag: bool) -> None: | ||
| if flag: | ||
| f: Function[[int], int] = a_function |
There was a problem hiding this comment.
If these type hints were not added would the type check fail? What if the two annotations were different?

Closes #162