📝Dot-call desugaring to function call

The idea is to desugar x.f(arg1, arg2) into f(x, arg1, arg2). Compilers are kind of doing that anyway for this.

It is also possible to desugar x.field to field(x).

  • allows piping style of programming

  • functions should be defined outside of classes

    • this pollutes the scope (e.g., because of this in Haskell no two structures in the same file can have fields with the same names)

      • § Multimethods seems to solve this. Instead of defining a new function, you can always add a method.

        • This might be not always desired, though.

  • For field desugaring, it makes it harder to implement x.field = value.

    • unless the compiler implements returning lvalues from the functions, or Clojure-like atoms

  • This adheres to Uniform access principle

Counterarguments

  • The following code behaves unexpectedly:

    type X = { x }
    fn print(x: X) = print(x.x)
    
    # because
    x.x == x(x)
    
    • as an option, warn when argument is called in a field position

    • lookup the field function ignoring non-functions (this would ignore the argument x and would link to global x)