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

use nested sum type to simplify panel enumeration #876

Merged
merged 2 commits into from
Nov 22, 2022

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Nov 21, 2022

This trick facilitates use of listEnums and more concise pattern matching.

Towards #873.

@kostmo kostmo requested a review from byorgey November 21, 2022 09:48
@kostmo kostmo force-pushed the nested-sum-type-names branch 3 times, most recently from 8b4b7b7 to 8973fe7 Compare November 21, 2022 23:21
mouseCoordsM <- Brick.zoom gameState (mouseLocToWorldCoords mouseLoc)
uiState . uiWorldCursor .= mouseCoordsM
REPLInput -> do
setFocus REPLPanel
Copy link
Member Author

@kostmo kostmo Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to here.

InventoryList -> Just RobotPanel
InventoryListItem _ -> Just RobotPanel
InfoViewport -> Just InfoPanel
REPLInput -> Just REPLPanel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from here.

@kostmo kostmo requested a review from xsebek November 22, 2022 15:22
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I assume the purpose is that now we can add new focusable panels without having to touch quite as many places in the code, since e.g. in some places you can just say listEnum and it will pick up all the focusable panels?

src/Swarm/TUI/Model.hs Outdated Show resolved Hide resolved
@kostmo
Copy link
Member Author

kostmo commented Nov 22, 2022

I assume the purpose is that now we can add new focusable panels without having to touch quite as many places in the code, since e.g. in some places you can just say listEnum and it will pick up all the focusable panels?

Yes, exactly. I add a new panel in #873.

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Nov 22, 2022
Comment on lines +322 to +326
Just (FocusablePanel x) -> ($ ev) $ case x of
REPLPanel -> handleREPLEvent
WorldPanel -> handleWorldEvent
RobotPanel -> handleRobotPanelEvent
InfoPanel -> handleInfoPanelEvent infoScroll
Copy link
Member Author

@kostmo kostmo Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's one more benefit of a dedicated sum type for Panels: we utilize exhuastiveness checking from the compiler here. The catch-all _ case no longer allows us to forget about a Panel; it instead handles all the non-panel Names.

@mergify mergify bot merged commit 3ad9132 into main Nov 22, 2022
@mergify mergify bot deleted the nested-sum-type-names branch November 22, 2022 21:54
mergify bot pushed a commit that referenced this pull request Jan 3, 2023
Code simplification, improved type safety (see [this comment](#876 (comment))).

This technique may also simplify the implementation of `CReverse` (see #950) if we choose to do so.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants