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

[refactor] pullports again, with StateT + mapM #64

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

acl-cqc
Copy link
Collaborator

@acl-cqc acl-cqc commented Dec 6, 2024

What's left of the earlier #62, reworked a bit.
StateT captures that we both pass the list of available things into pull1Port and then return the reduced version thereof; but rather than get, put and lift, using the StateT constructor and reordering the arguments.
Then mapM captures that each invocation of pull1Port returns a single thing that was pulled, or an error.

@acl-cqc acl-cqc requested a review from croyzor December 6, 2024 08:55
-> Checking ((a, ty), [(a, ty)])
pull1Port p available = case partition ((== p) . toPort . fst) available of
pull1Port :: PortName -> StateT [(a, ty)] Checking (a, ty)
pull1Port p = StateT $ \available -> case partition ((== p) . toPort . fst) available of
([], _) -> err $ BadPortPull $ "Port not found: " ++ p ++ " in " ++ showFn available
([found], remaining) -> pure (found, remaining)
(_, _) -> err $ AmbiguousPortPull p (showFn available)
Copy link
Collaborator Author

@acl-cqc acl-cqc Dec 6, 2024

Choose a reason for hiding this comment

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

One can imagine here (_, _) -> showFn available >>= err . AmbiguousPortPull p allowing showFn to use Checking i.e. showWithMetas in #54

@acl-cqc acl-cqc merged commit 05310cc into main Dec 6, 2024
2 checks passed
@acl-cqc acl-cqc deleted the acl/refactor_pullports2 branch December 6, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants