fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Usage of `:` in different contexts may be confusing

Open fridis opened this issue 1 year ago • 3 comments

Problem

Fuzion uses : for a number of very different purposes:

  1. to separate a feature signature from its inheritance calls f32(public val f32) : float is
  2. to create anonymous features ref : Any ...
  3. to define a constraint on a type parameter f(T type : numeric)
  4. as the implies operation in bool.infix :
  5. to construct a simple list h : tail
  6. 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

  1. inheritance:
    • C++: class child : parent { ...
    • Java: class child extends parent { ...
    • Eiffel: class child inherit parent ...
  2. anonymous features
    • Java: nothing: new Object() { }
  3. type parameter constraint
    • Java uses T extends Comparable<? super T>
  4. boolean implies
    • C, Java, C++, Python: use !a || b
  5. add element to head of list
    • Haskell: x : xs
    • Ocaml: x :: xs
  6. ternary operator
    • C, Java, C++: a ? b : c
    • Python: b if a else c

Possible alternatives

  1. stick with : or use inherits
  2. require is as in Any is ...
  3. stick with : or use f(T type inherits numeric) or f(T inherits numeric)
  4. unicode U+21D2: debug ⇒ 0 <= i < size
  5. use Ocaml's h :: tail, but what about Fuzion's 1 :: +1?
  6. unify ternary operator and match expression using a ? b | c.

Any commens, suggestions?

fridis avatar Jul 29 '24 13:07 fridis

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.

michaellilltokiwa avatar Jul 30 '24 08:07 michaellilltokiwa

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.

maxteufel avatar Jul 30 '24 13:07 maxteufel

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.

simonvonhackewitz avatar Jul 31 '24 07:07 simonvonhackewitz