-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding documentation for subtyping #1990
Adding documentation for subtyping #1990
Conversation
… account TailUnifVar and TailConstant
...ts/integration/inputs/typecheck/chaining_dictionary_function_record_dictionary_subtyping.ncl
Outdated
Show resolved
Hide resolved
doc/manual/typing.md
Outdated
Subtyping is a relation between two types where | ||
you can use one of the type in place of the other one. | ||
In Nickel, there is : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The beginning is a bit dry. The best way to introduce a notion is to motivate it, with an example. For example, start by saying something like:
While distinct types are usually incompatible, some types might actually be safely converted to some other types. Take the following example:
let extended : {_ : Number} = let initial = {foo = 1} in std.record.insert initial
And then go on to explain that technically the types don't match, but it's legal to "forget" some information to go from a record type to dictionary type.
And go on to explain why this is accepted while the types don't really match specifically.
…nction_record_dictionary_subtyping.ncl Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
I added motivation for subtyping. I was wondering do I add constructors(Array, Dictionary) in this pull request too or do I make another pull request to update the manual ? @yannham |
I think you can add it to this PR. It feels a bit artificial to split this in several ones, given the small changes all focused on the same file. |
I don't understand why my array example does not work. I didn't add to the manual Record/Record and Dyn subtyping for now because it is not implemented. |
I added a generic example for expanding a function to work around the fact that we don't have arrow subsumption. |
In this example, there is a silent conversion from `{foo : Number}` to `{_ : | ||
Number}`. This is safe because `foo` is of type `Number`, and it's the only | ||
field, which means that a value of type `{foo : Number}` is effectively | ||
dictionary of numbers. In the typing jargon, `{foo : Number}` is said to be a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dictionary of numbers. In the typing jargon, `{foo : Number}` is said to be a | |
a dictionary of numbers. In the typing jargon, `{foo : Number}` is said to be a |
Head branch was pushed to by a user without write access
In this pull request, I will add the manual documentation for subtyping(Record/Dictionary, Array/Array, Dictionary/Dictionary) and an integration test to chain functions on records.