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

Enable changing application state type in sub programs #168

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

istathar
Copy link
Member

@istathar istathar commented Feb 7, 2023

Introduce changeProgram to go from one top level type, Program τ, to another, Program υ.

This enables you to switch from a simple type when starting your application (Program None, say) to the actual user data type you intend to run at (Program Settings or whatever) once initialization is complete, thereby avoiding the hassle of needing an mempty value for the settings type just so you can get past configure.

Credit to @guaraqe who had the idea that this would be useful.

@istathar istathar added the core-program Issues involving the Program type and command-line options & argument parsing label Feb 7, 2023
@istathar istathar requested a review from guaraqe February 7, 2023 11:01
@istathar istathar self-assigned this Feb 7, 2023
@guaraqe
Copy link
Contributor

guaraqe commented Feb 7, 2023

I was going to push something almost identical, with type setupState :: Program α τ -> Program τ β -> Program α β, to be used as execute $ setupState setup action, the code was almost exactly the same but you bet it to me. Anyways, I approve!

@istathar
Copy link
Member Author

istathar commented Feb 7, 2023

Yours would be a little more "functional", certainly.

What I ran into today was the idea is having a different Settings type for each of the command modes. The binary I'm working on is already partially set up that way, which is what gave me the idea.

So for my use case, "figure out which type, then enter (with 3 different ones)" seems like a good pattern.

Will that be ok for you?

(Feel free to add a function with your design, too. We can have both!)

@guaraqe
Copy link
Contributor

guaraqe commented Feb 7, 2023

Of course, this one is just as good

@istathar istathar merged commit c00fa0e into aesiniath:main Feb 7, 2023
@istathar istathar deleted the change-program branch February 7, 2023 11:43
@dmvianna
Copy link
Contributor

dmvianna commented Feb 8, 2023

🙏🏼 Thank you for this! I will need to switch between libraries with different states, this saves me!

@istathar
Copy link
Member Author

istathar commented Feb 8, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-program Issues involving the Program type and command-line options & argument parsing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants