-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Should some values be self-typed? If so, which ones? #508
Comments
I'll ask the obvious three questions:
(Same questions apply to functions, although the answers might not be the same. I'm asking about numbers first since they're simpler.) I'm especially interested in question 2, just on the general grounds of innovation being scary. |
For what it's worth, assuming we want unique types for literals in the first place, I think it would be less surprising to most people if (eg) the type of |
I've been thinking about this a little bit, and I wonder if something a bit more ad hoc might be appropriate for integer literals. In particular, I would like the property that
|
The name in the literature for self-typed things (i.e. a type inhabited by exactly one value) is "singleton types". I'd be hesitant to use singleton types for number literals because they could |
One potentially-significant problem with having different behavior for two values of the same type like this is that you can't correctly forward a
C++ solves this problem in this particular case by defining a uniquely-typed |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
I don't know if this is helpful, but I've always thought that literals should be though of in classical mathematical terms (Peano) as pure syntactical expressions. So 1 is just a shorthand for 'successor(zero)', you can do the same for all basic language constructs (think in terms of functional languages or term-rewriting languages such as Pure and Maude) with an applicative transform to a canonical representation (normalization). Then you have a mapping to the implementation from the canonical form. If you combine this with flow-typing you might get something interesting (i.e. you apply constraints through flow-typing, reducing the set of corresponding concrete implementation types and if there is more than one left in the end, maybe you can use a priority scheme). Ole-Johan Dahl's 1990s introduction-level book "Verifiable Programming" shows this for basic programming language types as showed in this simple presentation without the verification aspect . (Anyway, I am somewhat disappointed that "simplified" term-rewriting and flow-typing isn't used more in mainstream metaprogramming/generic programming. Even something limited, such as XQuery/XSLT could be quite potent.) |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
Proposal #2360 offers an answer to this question: only |
There is also the question: "Do we want unique types for numeric literals and functions?" There last remaining question is whether functions have a unique type. |
Agreed, in practice I think we've decided "yes" here, but we should confirm that.
I don't think we have an answer here, but I also don't think we need one in this issue. I'd suggest following up with a fresh question there once we have a better idea of how callable stuff should work. |
Confirmed with leads, and we're happy with the answers summarized here: |
There are a number of contexts in which we have suggested that certain values should have unique types. Moreover, there have been suggestions that we can define the type of certain values as being the same entity as value itself (notably, we say the type of the empty tuple
()
is the empty tuple()
). We could employ this lifting of values to the type level in general for values that should have unique types, forming in each case a type with exactly one value, where that value is the type itself.The cases to which we might want to apply this include:
((), (), ())
)Examples:
Note that this has a potential foundational concern: repeatedly asking for the type of a value, and then that type's type, and so on, will not in general converge to
Type
, but I'm not sure that's a fundamental problem. (I think it's plausible that we'll want to modelType
as an interface rather than as a type-type.)So there are two questions here:
The text was updated successfully, but these errors were encountered: