Question about subtyping
See original GitHub issueHello, I’m studying Grace and curious about the way it handles type inference with subtyping.
So consider this case which TYPES ok:
; cabal run -- grace interpret --annotate - <<< '[{answer: null}, {answer: 42}]'
[ { "answer": null }, { "answer": 42 } ] : List { answer: Optional Natural }
and this which FAILS:
; cabal run -- grace interpret --annotate - <<< '[{answer: 42}, {answer: null}]'
Not a subtype
...
So the depending on the order of elements in the list it either succeeds or fails which can be then fixed (suggested by the README) by adding a type annotation with an existential List ?
:
; cabal run -- grace interpret --annotate - <<< '[{answer: 42}, {answer: null}] : List ?'
[ { "answer": 42 }, { "answer": null } ] : List ?
I think this can be a bit confusing to users (that in those two similar cases they either required or not to add type annotations). Do you think it’s worth fixing and/or possible to fix by synthesising List ?
type for List
constructor?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
A Subtyping Question
Suppose the language imposes the following rules when it accepts TypeTPrime as a subtype of TypeT: TypeTPrime's method must return a subtype of...
Read more >Question Types and Subtypes - ServiceNow Developers
Question type Question subtype Description
Text Single‑line Enter a single line of text.
Text Multi‑line Enter multiple lines of text.
Text Rich text Enter HTML text...
Read more >type systems - What are the problems of subtyping?
Yes, as soon as the type system has subtyping, you need something like sealed or final types to make the non-subtyping assumptions.
Read more >Answering the subtype question - Scala Contributors
Can someone explain how the subtypep question is answered within the Scala compiler, and presumably in user-land within Scala macros.
Read more >Subtyping - Wikipedia
In programming language theory, subtyping is a form of type polymorphism in which a subtype is a datatype that is related to another...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think higher rank polymorphism is important for a configuration language. The main reason I went with the bidirectional type-checking algorithm is because out of all the algorithms I tried it seemed the easiest to extend with new features
Just to clarify — the “Local Type Inference” paper uses bidirectional type checking (in fact I’ve seen many cite it as the first paper describing it, though they themselves say that this is folklore).
But nevertheless, you’re right, the change is probably not so trivial and I’m not sure how well it can be combined with polymorphic subtyping which Grace has now. So this issue can probably be closed.
By the way — do you think higher rank polymorphism is important for a configuration language (I don’t have a good intuition where it can be used)?