-
Notifications
You must be signed in to change notification settings - Fork 4
Add generator overriding #88
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?
Conversation
130f5d3
to
2618ae7
Compare
2618ae7
to
503019d
Compare
a0b2f87
to
2a82948
Compare
d146220
to
60b5593
Compare
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.
Here is some of my feedback. I'll think more about what can we do about the problem that we now store a function in a type that has Show and Eq instances, whcih should never be the case
.github/workflows/ci.yml
Outdated
- name: Install fourmolu | ||
run: | | ||
FOURMOLU_VERSION="0.18.0.0" | ||
FOURMOLU_VERSION="0.15.0.0" |
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.
What's the reason for the downgrade?
This caused a whole bunch of unnecessary diff. Could you please revert it and undo all of the unrelated changes?
= SingleTerm Term | ||
| PairTerm Term Term | ||
| GroupTerm [WrappedTerm] |
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.
Why not just name the actual constructors? I don't see a point in pattern synonyms
= SingleTerm Term | |
| PairTerm Term Term | |
| GroupTerm [WrappedTerm] | |
= S Term | |
-- ^ Single Term | |
| P Term Term | |
-- ^ Pair Term | |
| G [WrappedTerm] | |
-- ^ Group Term |
| MRuleRef Name | ||
deriving (Functor, Show) | ||
|
||
deriving instance Show (CTree MonoRef) |
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.
Inability to derive Show, Eq and Generic is very error prone and it would be better to avoid if possible. Looking at Hashable instance makes me cry.
Unfortunately, I do not have a suggestion how to avoid it. 😞
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.
It might be possible to replace CBORGenerator
with a type parameter in the definition of CTree
and then use some dummy type for implementing these instances.
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.
Nicer than this would be to wrap the generator function into a synthetic type that has overridden Eq, Show, Ord instances
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.
In other words, make CBORGenerator
a (bad) instance of these things.
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.
In other words, make CBORGenerator a (bad) instance of these things
I did think about that, but that just moves a problem to a different place.
Problem with this approach in general is that you cannot provide a lawful instance for Eq when type contains a function and thus you could easily break referential transparency, which is one of the things we really like Haskell for 😁
It could be argued that it is not a big deal in this case, and it is true, but it does make me cringe looking at it.
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.
I think it would make sense to add some index type to the AST anyways, because that would let us use trees that grow to have a different AST representation for each purpose. For example we don't need generators at all if we only use that AST to pretty-print, so the pretty printing AST could have a unit type in place of the generator. Similarly we can get rid of the comments field if we're using the AST for verification, so the verification logic doesn't need to deal with comments at all.
Co-authored-by: Alexey Kuleshevich <[email protected]>
Co-authored-by: Alexey Kuleshevich <[email protected]>
Co-authored-by: Alexey Kuleshevich <[email protected]>
78bda12
to
53e5540
Compare
This PR makes it possible to specify custom CBOR generators for specific rules. This can be useful when it is not possible to specify all of the constraints using CDDL's control operators, but you still want to have the generator generate valid data for your test cases.