typesannotationshy

Function Type Annotations


I think Hy is fantastic! Plan on using it, possibly even hacking on it.

I've noticed type annotations are supported, but apparently only for variables, and at most, function arguments. It doesn't seem possible to type annotate function (or method) return values.

Is this potential feature planned for the future? Or is it simply deemed not practical or worth the effort at the moment?

Keep up the great work!


Solution

  • Update

    Function-type annotations are documented along with the macro defn. They look like

    (defn  #^ int  foo [x]
      (+ x 1))
    

    or alternatively

    (defn (annotate int) foo [x]
      (+ x 1))
    

    Original answer

    They're implemented, just not documented, so far as I can tell. The syntax is

    (defn foo ^int [x] (+ x 1))
    

    to declare a return value of type int.