matthewcrews / tractor-language

Place to keep thoughts a CLR language for computation
MIT License
6 stars 0 forks source link

Potential UFCS ambiguities #1

Open KoziLord opened 1 year ago

KoziLord commented 1 year ago

Assuming that there's even support for expr pointers in Tractor, there's a potential ambiguity between invoking a struct's expr pointer and a freestanding function using UFCS.

Add :: expr(a : Vec2, b) -> Vec2

Vec2 :: struct
    X : f32
    Y : f32
    Add : expr (a : f32, b) -> f32

val := v1.Add(v2) //Do we access v1's Add field and call it or do we call the freestanding Add expr?

In my opinion, this presents two issues: A: You don't exactly know if the dot operator in this case is accessing the variable or not B: There is a chance of a collision as demonstrated in the snippet above.

When solving the same problem myself, I've decided to steal F#'s/JS' pipe operator which makes UFCS very explicit and makes the dot operator exclusively access fields.

v1.Add(v2)
v1=>Add(v2)
matthewcrews commented 1 year ago

Thanks for pointing this out. That is an excellent point I didn't consider.