-
Notifications
You must be signed in to change notification settings - Fork 32
Any type #271
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
base: master
Are you sure you want to change the base?
Any type #271
Conversation
…interfaces. There are still a few dirty hacks and TODOs present.
This missing implementation could for example cause problems when Any is used in a type parameter
…interfaces. There are still a few dirty hacks and TODOs present.
This missing implementation could for example cause problems when Any is used in a type parameter
|
You can add a type declaration into the standard library even when there's no constructors; we do this for strings, numbers etc. |
The previous implementation of Any required implementation of a lot of logic for special cases. This reimplementation builds Any upon the DataTypeType class and therefore a lot of the code for these special cases could be removed.
Thank you for that hint. My latest commit now reimplements Any using a "data Any;" declaration and I was able to remove the special cases. I also added some additional tests. As a sanity check, before continueing with the pull request, I would like to first merge back this reimplementation into my thesis project and check if everything still works. I think I can do this on monday. |
|
Re your point 2, we currently have not only equality comparison but also ordering (less-than) in ABS -- see https://abs-models.org/manual/#sec:pure-expressions, subsection "Semantics of Comparison Operators". With I anticipate the next thing after |
Hmm, if possible I would like to try to avoid adding explicit additional run-time type info to values, since then we would need to adapt most of the erlang backend to be compatible with the new data format, if I'm not mistaken. Instead, I would try to infer the type from the current representation as By the way, by how many/which backends should the Any type ideally be supported for now? Would it be sufficient to implement comparisons for Erlang?
My use case for comparisons across types was restricted to equality comparisons of future references (see first post). Should we implement a less-than hierarchy like Erlang without knowing whether someone will use it in the near future? We could also define the result of all comparisons across types to be What do you think? |
Erlang is sufficient, yes. |
I learned through experience that adding a feature specialized to my own use case leads to unhappy users, who reasonably expect generality and orthogonality of features. That's the price of working on a tool with users that I don't personally know. (The reward, of course, is also working on a tool with users that I don't personally know.)
A medium-term goal for me is to redefine sets and maps to use red-black-trees or similar; in that case we have to have an ordering relation. This would mean we couldn't have We should have an arbitrary ordering, e.g., future < reference < string < number < user-defined datatype, and compare user-defined datatypes similar to https://abs-models.org/manual/#sec:pure-expressions, subsection "Semantics of Comparison Operators" (where we describe how we compare terms with different constructors of the same user-defined datatype). In erlang, we would need to add the name of the datatype to values, or add a constructor -> datatype name mapping (constructor names are already contained in values, since we use them for pattern matching). Anyway, I could have a look at implementing this if you agree that the semantics are basically sane. |
|
You are right that adding a new type which does not support the less-than operation is probably a bad idea since it would create a special case for the users and the language, as it is the only type which does not support it. Also, just defining the result of a less-than comparison of different types to be always As we discussed in Gitter, quite a lot of type information can already be extracted from the runtime representation. However, there are some cases where explicit type annotations will be required. For example, for empty lists we can't derive the type of the elements it stores at runtime:
I don't want to increase your workload due to an issue I caused. So if we are not in a hurry, I could also look into implementing this. However, I'm quite busy for the next few weeks and will probably only be able to pick this up again in the middle of March : / |
|
There's also always the possibility of restricting the less-than operator to numbers and strings. We would lose the possibility of generalized sorting and container implementations, but gain implementation efficiency. If I remember correctly e.g. Reiner was in favor of eliminating the general less-than operator, but not enough so to make a strong case for it. Please do keep reminding me about this issue; I would not want to be a bottleneck for developing ABS. If this issue is still open at the ABS workshop in Torino, I will bring it up then. |
I'm not sure if there's a more sophisticated argument to be made here, but I'd make a case that the code above is equivalent to the following, which is trivially true: |
|
I created a new branch and opened a new pull request for introducing the restricted version of Any that we discussed: #309. This is because I based that new version on the current state of master and I want to preserve the old branch for reference. |
This branch implements a new type
Anyat the top of the type hierarchythat is
I needed this Any type for my thesis, where I implemented user-defined
schedulers based on Register Automata which stored futures in register fields.
I required these registers to be able to store any future and thus they had to be
of the type
Fut<Any>.@Edkamb asked me now to create a pull request for the Any type feature, so here
it is :).
However, during my implementation of Any, I focused on getting it to work for my
use-case, therefore there are still some issues which might need to be resolved
before merging:
1. Edit: The issues stated in this section have now been resolved by adding a
data Any;declaration to the stdlib, see the comments below this post.I did not add a type declaration for Any in the stdlib, since there is no
syntax for it.
This leads for example to some unsightly hacks during lookups, like this
one in
src/main/java/org/abs_models/frontend/typechecker/TypeResolution.jrag:(See also the other remaining
TODOs within the changed files)One possibility of resolving this would be to add a built-in
CompililationUnitto every compilation process which contains theAnyTypeDecl, similar to how the stdlib is added.I already implemented this with a few related changes in a second branch
https://github.com/ahbnr/abstools/tree/commonSupertype_cleanup, see for example
org.abs_models.frontend.parser.Main::getBuiltinUnitand the uses of thatfunction.
However, there is still a bug, which causes compilation to fail when
programmatically adding
AnyTypeDeclto a list of declarations inorg.abs_models.frontend.parser.Main::getBuiltinUnitwhich I could notinvestigate yet.
Strangely enough, this bug appears for me only when executing tests,
not when directly compiling files.
2.
Anywas useful to me, since it allowed me to compare aFut<Any>registerto any
Fut<T>value (equality comparison), which worked for me with the Erlangbackend.
However, I'm not quite sure, how the backends (should) handle comparisons
across types, for example:
So this issue probably needs to be discussed / the backends be checked how
this is handled.
I added a few tests for
Anyinorg.abs_models.backend.common.AnyTestsandin
org.abs_models.frontend.typesystem.AnyTypeTests.