-
Notifications
You must be signed in to change notification settings - Fork 30
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
How to look up type and bounds of array element? #109
Comments
This is actually somewhat tricky. But definitely worth doing. |
Seems related to #59, which has been open for quite some time. |
It is 'morally' related to #59, but in terms of implementation, these two are entirely disjoint. The question I have about this issue is whether the desired semantics are to check that the index is valid (and produce the most specific type known about that index), or to assume it is valid (and to not examine the index at all, and to produce the type which holds for every element of the array). Based on the example, I think the desired output is
(that is, the former of the above two options). If that's the case, is it still correct to take the latter option when no information is known about the index (e.g. |
I believe your guess is correct, but we'll need to wait for @ccshan to chime in. My guess would be that in all cases you return the best information you can (including knowing nothing) rather than returning an error. |
To elaborate on my question, consider the (trivial) example:
(note: when I said "produces an error", I should have said "returns FAIL"). Should the new semantics produce |
Given that we currently have no way in (concrete) Hakaru to express an array full of bounded
(except Moreover (contrary to "the former of the above two options"), it would be nice if we don't check that the index is valid, even as we use the index for information. |
So why not check if an index is valid? In some sense, I see several cases:
If we had the invariant "by the time that an index is dereferenced, then it is always valid" [i.e. in the operational semantics], then we could certainly make 'nice' assumptions. But is that invariant actually true? If it's not, then I think we're introducing a very sneaky source of bugs. |
Here's my rough reason to not check if an index is valid: it's natural for a programmer to write something like |
That is explicitly why I spoke of invariants. I should have added the word 'global' in there, I guess. Down this road lies much pain. This is the road that led CASes like Maple to always turn But I guess we can always say that Hakaru works along the lines of "Well, if you're too lazy to say what you mean, we'll guess, and sometimes we'll be wrong. But we will give you no indication whatsoever what guess we made, or even that we made a guess." That is certainly very consistent with Maple. |
PS: it is also very natural for programmers to write junk. Many current mainstream programming languages build that attitude right in. Program transformations (which are kinds of symbolic computations) have this way of making this much worse, unlike just running the program, which somehow does not 'blow up' junk nearly as badly. In other words: I don't buy arguments of the kind "it's very natural for programmers to do X". That kind of entropy gives us Go as somehow being 'modern'. The whole point of using Haskell (for example) is to get away from the kinds of mistakes too easily done by this very kind of thinking!!! |
In the case of
in which case, I think A stronger type system in Hakaru could help users express invariants about their code without risking throwing any errors, as well as help machines processing that code understand that the user intends to use their program in only particular ways. e.g. the above could have the stronger (currently inexpressible) type The above example is in contrast to |
I was definitely not thinking of these as types, to be dealt with in a 'type system'. Guards, sure. Annotations even. |
It is not essential to me that we do not check that the index is valid. What's essential to me is what I said to be essential above. Regarding that, @yuriy0, there's no way to get an upper bound 1 because the Hakaru type |
The handy function
KB:-getType
is used athakaru/maple/Summary.mpl
Line 215 in 27de978
idx
expressions?More concretely, this works:
And it would be nice if this were to work too:
The text was updated successfully, but these errors were encountered: