Skip to content

Typings bikeshedding #999

@vendethiel

Description

@vendethiel

Some time ago (#803) I had started working on a PR to add type hints to the language.

That's still something I miss to this day, so I want to bring it back up.
There were a lot of discussions, so I think we should try to discuss it beforehand.

Typing symbol

I suggested the symbol @: to add a type annotation. Someone suggested ^. @gkz suggested ::.

The reason I want(ed) not to use :: is because it's rewritten to ID:prototype when it's parsed directly, at which point we have no info on whether it's going to be part of a signature of just a Parens (we only tag () as PARAM( and PARAM) after seeing ->).
We'd need to go through the tokens to mark ID:prototype as ASCR (or whatever else). We'd also need to be careful not to tag in "defaults" – that is, (x = -> ::) ->, (x ? ::) ->, (x and ::) ->, etc...

where to allow typings

I'd suggest we only allow type annotations in:

  • function declarations (function and ->/<-/...)
  • var
  • let

generics

I have one suggestion: [T](xs @: Array[T]) ->. The reason I suggest [] rather than <> is mostly for parse-ability (and because I'm used to Scala...). Tagging []() -> is easier than the ambiguities with <>, we just have to look for a ] when re-tagging a ( as a PARAM(, and cycle back to [ from there (since an array is never callable anyway).
(since [T]() -> and xs[T]() -> make no sense anyway)

Parsing the @: Array[T] part is harder, but still simpler than @: Array<T>, where the > would be parsed as a BIOP because it's directly followed by a )...


@rhendric I'm interested in your PoV, because it's a sensible topic, considering all the ambiguities to keep in mind :-).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions