Skip to content
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

Add missing ToJSON instances #347

Closed
xsebek opened this issue May 28, 2022 · 7 comments
Closed

Add missing ToJSON instances #347

xsebek opened this issue May 28, 2022 · 7 comments
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Game State An issue having to do with the game state record. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. L-Pretty-printing Pretty-printing ASTs or values into a string representation. S-Moderate The fix or feature would substantially improve user experience. Z-Feature A new feature to be added to the game.

Comments

@xsebek
Copy link
Member

xsebek commented May 28, 2022

I would like to have ToJSON to complement the current FromJSON.

@xsebek xsebek added Z-Feature A new feature to be added to the game. C-Moderate Effort Should take a moderate amount of time to address. S-Moderate The fix or feature would substantially improve user experience. L-Pretty-printing Pretty-printing ASTs or values into a string representation. labels May 28, 2022
@xsebek
Copy link
Member Author

xsebek commented May 28, 2022

We would probably want to create a custom class given that we need some environment references.

Though at the top level I would not mind just splicing in the entire data.yaml and entities.yaml, they are not that long. 😏

@xsebek xsebek changed the title Add ToJSON instances Add missing ToJSON instances May 28, 2022
@TristanCacqueray
Copy link
Collaborator

What about CESK machine, is it possible to implement the full serialization of its state and the continuation Frames? Or is there a more desirable encoding strategy?

It seems like we would need to add many instances, should they be added to each modules, or should we collect them all in an extra module using orphaned instances?

@byorgey
Copy link
Member

byorgey commented Jun 26, 2022

It is definitely possible to fully serialize a CESK machine --- in fact, part of the original reason I chose to use something like a CESK machine is that it represents higher-order functional programs in a completely first-order way, making it possible to serialize them. (As mentioned elsewhere, WorldUpdate and RobotUpdate actually contain functions and hence make this impossible at the moment --- but we can and should replace them with first-order representations that enumerate the specific types of update functions we need.)

@byorgey
Copy link
Member

byorgey commented Jun 26, 2022

It seems like we would need to add many instances, should they be added to each modules, or should we collect them all in an extra module using orphaned instances?

At the moment it seems we have gone with having each instance live in the same module as the data type it is for, so I guess we should stick with that approach for now. There are pros and cons to either choice.

mergify bot pushed a commit that referenced this issue Jul 11, 2022
@byorgey byorgey added G-Game State An issue having to do with the game state record. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. labels Sep 20, 2022
@xsebek
Copy link
Member Author

xsebek commented Nov 10, 2022

The autodocodec package has a lot features we want and looks nice:

It might be worth investigating if it can work with select parts requiring environment.

@byorgey
Copy link
Member

byorgey commented Jun 26, 2023

I'm unsure at this point which types are still missing ToJSON instances, and I'm honestly not sure how to check. I asked this question, we'll see if anyone has any good ideas for how to figure it out:

https://discourse.haskell.org/t/listing-types-with-or-without-a-certain-type-class-instance/6687

More relevant info: https://gitlab.haskell.org/ghc/ghc/-/wikis/hie-files

Some Template Haskell code that may be helpful:

$(do
     info <- reifyInstances ''ToJSON [VarT (mkName "a")]
     runIO $ print [ty | InstanceD _ _ (AppT _ ty) _ <- info]
     return []

@byorgey
Copy link
Member

byorgey commented Jun 11, 2024

At this point I think we have ToJSON instances for pretty much everything, including CESK --- I am not aware of any important types with missing ToJSON instances. The big problem now is serializing to something small (#1907). I am going to close this issue, and if we discover any types with a missing instance we can create individual issues for them as necessary.

@byorgey byorgey closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-Game State An issue having to do with the game state record. G-Scenarios An issue having to do with scenario design, the way scenarios are described and loaded, etc. L-Pretty-printing Pretty-printing ASTs or values into a string representation. S-Moderate The fix or feature would substantially improve user experience. Z-Feature A new feature to be added to the game.
Projects
None yet
Development

No branches or pull requests

3 participants