-
Notifications
You must be signed in to change notification settings - Fork 57
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
Define generic implementations of Struct
and Typed
methods. Refs #564.
#566
Open
RyanGlScott
wants to merge
5
commits into
Copilot-Language:master
Choose a base branch
from
GaloisInc:develop-generic-struct-typed-methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Define generic implementations of Struct
and Typed
methods. Refs #564.
#566
RyanGlScott
wants to merge
5
commits into
Copilot-Language:master
from
GaloisInc:develop-generic-struct-typed-methods
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ods. Refs Copilot-Language#564. This adds functionality for implementing the class methods of `Struct` and `Typed` using `GHC.Generics`. As such, one can now easily define instances of these classes by deriving a `Generic` instance for the struct data type, i.e., ```hs data MyStructType = ... deriving Generic instance Struct MyStructType where typeName = typeNameDefault toValues = toValuesDefault updateField = updateFieldDefault instance Typed MyStructType where typeOf = typeOfDefault ``` This work is based off of an initial implementation by Marten Wijnja (@Qqwy). Note that I do not yet change any of the default implementations of any `Struct` or `Typed` methods. This is because several `Struct` instances in the wild currently do not define implementations of `updateField`, and moreover, they also do not define `Generic` instances for the corresponding data types. As such, changing the default implementation of `updateField` to use a `Generic`-based default would cause these instances in the wild to no longer compile. We will explore changing the default implementations after a suitable transition period. Co-authored-by: Marten Wijnja <[email protected]>
…opilot-Language#564. In the future, we plan to change the default implementation for `updateField` such that it will require a `Generic` instance. This will break any existing `Struct` instance that omits an implementation of `updateField` and also does not define a `Generic` instance for the struct data type. Unfortunately, there does not appear to be a way for GHC to warn about this combination of properties, but we can at least warn about this in the `updateField` Haddocks.
…. Refs Copilot-Language#564. Using recently added `Generic`-based implementations, much of the boilerplate code needed to define `Struct` and `Typed` in the struct-related `copilot` examples can be replaced with much simpler implementations. Note that I have intentionally _not_ used `updateFieldDefault` in the `StructsUpdateField.hs` example, as that example is intended to demonstrate how one would implement `updateField` by hand. This work is based off of an initial implementation by Marten Wijnja (@Qqwy). Co-authored-by: Marten Wijnja <[email protected]>
RyanGlScott
force-pushed
the
develop-generic-struct-typed-methods
branch
from
November 13, 2024 21:12
0c90e55
to
606abcb
Compare
RyanGlScott
commented
Nov 13, 2024
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds functionality for implementing the class methods of
Struct
andTyped
usingGHC.Generics
incopilot-core
. As such, one can now easily define instances of these classes by deriving aGeneric
instance for the struct data type, i.e.,This work is based off of an initial implementation by Marten Wijnja (@Qqwy).
Note that I do not yet change any of the default implementations of any
Struct
orTyped
methods. This is because severalStruct
instances in the wild currently do not define implementations ofupdateField
, and moreover, they also do not defineGeneric
instances for the corresponding data types. As such, changing the default implementation ofupdateField
to use aGeneric
-based default would cause these instances in the wild to no longer compile. We will explore changing the default implementations after a suitable transition period.I have also modified the struct-related
copilot
examples to implement theirStruct
andTyped
instances using these new functions. Note that I have intentionally not usedupdateFieldDefault
in theStructsUpdateField.hs
example, as that example is intended to demonstrate how one would implementupdateField
by hand.Fixes #564. Supersedes #516.