Skip to content

Add type annotations #5

@J3RN

Description

@J3RN

Any expression should be allowed to have an associated type annotation. Haskell has a similar feature using ::, e.g.

(1 + 5) :: Int

Since functions are lambdas assigned to a name, we would also want this for lambdas (as Haskell allows):

(\x -> x + 1) :: Int -> Int

However I think making it postfix would have poor usability:

inc = (x) -> { x + 1 } :: (Int) -> Int

Ergo, I would suggest using a prefix notation:

inc = (Int) -> Int :: (x) -> { x + 1 }

I'm not super in love with this either. Haskell also allows a "declaration" above a definition, which might work better:

inc :: (Int) -> Int
inc = (x) -> { x + 1 }

I think this is rather good, but with the requirement that all expressions may be typed, we would need multiple syntaxes. Maybe the former can be stylized:

inc = (Int) -> Int
   :: (x) -> { x + 1 }

This could be acceptable.

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