fathom
fathom copied to clipboard
Implement surface syntax for a selection of binary operators.
Not sure which binary operators to support, but I expect at a minimum it would be nice to implement:
<term1> + <term2>: addition<term1> - <term2>: subtraction<term1> * <term2>: multiplication<term1> / <term2>: division
The idea is that these will be elaborated to the appropriate primitive operation. In order to do this initially we'd need to synthesize the types of the operands, which could be frustrating for users, especially when using literals. For example:
let test1 : U32 = 3 + 2; // error: ambiguous integer literals
let test2 = (3 : U32) + (2 : U32); // ok
let test3 =
let x : U32 = 3;
let y : U32 = 2;
x + y; // ok
...
Ultimately we'd want to use postponement and unification to resolve these, but that would take some more effort. This would hopefully allow for the following code to be elaborated:
let test1 = 3 + 2;
let test2 : U32 = test1;
...
A limited form of unification would require one of the operands to have a known type, at least! Then x / 2 would be okay.
Hmm, just thinking that actually we can do it bidirectionally in checking mode, based on the return type. No unification required.
But yeah you are right if there is no known return type, then you'd need to know the type of one of the operands? Does also depend on if we want to have multiple overloads for different type combinations but that makes me nerrrvous. 😬
Wasn't this resolved by https://github.com/yeslogic/fathom/pull/377?
Yep 👍