Usage of `:` in different contexts may be confusing
Problem
Fuzion uses : for a number of very different purposes:
- to separate a feature signature from its inheritance calls
f32(public val f32) : float is - to create anonymous features
ref : Any ... - to define a constraint on a type parameter
f(T type : numeric) - as the implies operation in
bool.infix : - to construct a simple list
h : tail - to separate the middle and the last argument in the ternary operator
? :
This might confuse the user since a : b could mean completely different things.
Other languages
What are the alternatives? Here is what I found in other languages
- inheritance:
- C++:
class child : parent { ... - Java:
class child extends parent { ... - Eiffel:
class child inherit parent ...
- C++:
- anonymous features
- Java: nothing:
new Object() { }
- Java: nothing:
- type parameter constraint
- Java uses
T extends Comparable<? super T>
- Java uses
- boolean implies
- C, Java, C++, Python: use
!a || b
- C, Java, C++, Python: use
- add element to head of list
- Haskell:
x : xs - Ocaml:
x :: xs
- Haskell:
- ternary operator
- C, Java, C++:
a ? b : c - Python:
b if a else c
- C, Java, C++:
Possible alternatives
- stick with
:or useinherits - require
isas inAny is ... - stick with
:or usef(T type inherits numeric)orf(T inherits numeric) - unicode U+21D2:
debug ⇒ 0 <= i < size - use Ocaml's
h :: tail, but what about Fuzion's1 :: +1? - unify ternary operator and match expression using
a ? b | c.
Any commens, suggestions?
I very much agree with the problem. I don't see an issue with having a keyword inherits and don't mind the additional typing in this case. So this is what I would prefer currently.
I personally don't mind any of this, and don't find it confusing. There are features in the base library that I mix up more often than this.
I personally don't like alternative 4, using ⇒ for the pre-/postcondition qualifiers, because it looks similar to a feature declaration and can not simply be typed on the keyboard. Other than that I have no strong opinion on this.