evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.08k stars 39 forks source link

cast as syntax #173

Open trans opened 7 years ago

trans commented 7 years ago

Just read your "Lately in Kitten" article. Was wondering why you chose the verbose notation:

1.0 cast as (Float32)

At the very least why not just

1.0 as (Float32)

But probably more important, why not RPN form, e.g.

1.0 (Float32) cast
evincarofautumn commented 7 years ago

cast is going to be the trait for enabling conversions between types. as (Type) is the identity function on Type, so it just constrains the result, and it’s only necessary if the return type is ambiguous. For example, if foo has type Float32 -> Float32, then the type of cast in 1.0 cast foo is unambiguous, and no type annotation is necessary.

If cast as becomes a pain point, we could add sugar for it, e.g., to (Type).

The reason it’s not postfix is that Kitten parses types differently from terms, so there needs to be an indicator to the compiler that it should switch from term to type. That could be relaxed at some point (e.g. #132).