Operator member syntax

The qualified operator lookup syntax does not solve the overload ambiguity problem. Qualified name lookup for non-operators does not solve that problem either. Thus I think overload ambiguity is almost entirely orthogonal to the operator member syntax proposed here.

There are two reasons qualified operator lookup is desirable:

  1. This always seems like a missing feature, because qualified reference to a static non-operator member is already possible.

    let f = Float.maximum // (Float, Float) -> Float
    let g = Float.+ // error, but why not?
    
  2. It improves clarity for potential language features that retroactively provide a behavior to an existing method. This includes dynamic replacement and differentiable programming.

    @dynamicReplacement(for: Foo.+)
    func +(_: Foo, _: Foo) -> Foo { ... }
    
    @derivative(of: Foo.+)
    func derivativeOfAdd(_: Foo, _: Foo) -> (value: Foo, differential: (Foo, Foo) -> Foo) { ... }
    
1 Like