Conversation
b5b7230 to
410dcbc
Compare
| case InfixApp(lhs, Keywrd(op : (Keyword.`<:`.type | Keyword.`:>`.type)), rhs) => | ||
| Term.SubConstr(constraint(lhs, op, rhs)) |
There was a problem hiding this comment.
Conceptually clean pattern but I must say the Scala syntax is so heavy here 😔
There was a problem hiding this comment.
How would you suggest to make it better?
There was a problem hiding this comment.
I think it's mostly me being a x.type hater. I think values should be automatically lifted to singleton types when appearing in type positions. I also don´t like how Scala has both the bind @ pattern and bind : type syntaxes, the former should ideally subsume the later IMO. I also don't like how I had to use parentheses around the union.
There was a problem hiding this comment.
Yeah, all these things should be addressed in MLscript/Witt 😛
InfixApp(lhs, Keywrd(Keyword.`<:` | Keyword.`:>` as op)), rhs) then
Term.SubConstr of constraint(lhs, op, rhs)(At least that's the syntax I envision.)
In Scala, x can't be used as a type due to the separate namespaces. When they introduced literal types, they briefly debated whether to make it 2.type (for consistency) or just 2, but they opted for the latter because it's just much nicer.
46c5ce1 to
414cf0c
Compare
|
@LPTK Should I also add a |
Can you make it type (>:>) Sup[A, B] = Sub[B, A]? IDK if this will work, but it should (if it doesn't, you could fix it). |
|
@LPTK Using the following works but the precedence is higher than most other type constructs so I have to put parentheses around most types on each sides (unions, intersections, arrows...), do I just accept the drawback or do you have an idea to solve that? |
|
Ah right, because the precedence is inferred from the first and last characters ( |
|
Okay, I pushed a commit with the following changes:
This simplifies the code at the cost of wrong/annoying precedence (requires parentheses for many composed types). |
|
Actually if precedence is that important, why don't you just use |
|
@LPTK I think that would make the syntax of constrained and universal types ambiguous: |
|
Yes, but I was talking about your top-level constraint testing use cases. The |
|
Hhhhm, I just checked and actually it doesn't seem to work for the top-level case either: I can make it work but I think I will just accept to use parentheses IMO. |
Well of course, since |
|
Edited my message at the same time as you sent yours 😅 Anyway, I kind of like having the same syntax for constraints in constrained types and at the top-level, parentheses are not that big of a deal IMO. |
Allow writing subtyping constraints at the top level, which is not meant to appear in real programs but can be useful to write tests (I do that !).
Example: