question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about subtyping

See original GitHub issue

Hello, 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Gabriella439commented, Nov 9, 2021

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

0reactions
andreypoppcommented, Nov 9, 2021

I don’t think this is fixable short of overhauling the type checker to use something other than bidirectional type inference.

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)?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found