-
Notifications
You must be signed in to change notification settings - Fork 3
Abstract toMatching and matchCdOdSolution over hardcoded CD/OD counts #597
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
Conversation
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
|
@copilot: For the |
…chCdOdSolution Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Changed |
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
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.
Pull request overview
This PR updates the MatchCdOd task’s evaluation/solution logic to work with the actual set of class-diagram keys in the instance, instead of assuming exactly two CDs (and a fixed OD set), making the code resilient to instances with variable diagram counts.
Changes:
- Generalized
toMatchingto accept the list of CD keys and to iterate viaM.toListover OD mappings. - Updated
matchCdOdEvaluationto passM.keys (diagrams task)intotoMatching. - Updated
matchCdOdSolutionto derive CD keys fromdiagrams taskinstead of hard-coding[(1, []), (2, [])].
| toMatching :: [Int] -> Map Char [Int] -> Map (Int, Char) Bool | ||
| toMatching cds m = | ||
| M.fromList [((cd, od), cd `elem` cdList) | cd <- cds, (od, cdList) <- M.toList m] |
Copilot
AI
Feb 10, 2026
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.
The new abstraction for variable CD keys/OD keys (in toMatching and matchCdOdSolution) isn’t covered by the existing MatchCdOdSpec tests (they mostly cover instance generation and getODInstances). Consider adding a unit test that constructs a MatchCdOdInstance with non-default diagrams keys (e.g., 3+ CDs and/or non-1/2 keys) and asserts matchCdOdSolution/toMatching produce the expected mappings.
| matchCdOdSolution task = M.toList $ reverseMapping (fst <$> instances task) | ||
| where | ||
| reverseMapping :: Map Char [Int] -> Map Int Letters | ||
| reverseMapping = fmap (fmap Letters) . M.foldrWithKey |
Copilot
AI
Feb 10, 2026
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.
reverseMapping = fmap (fmap Letters) ... looks ill-typed / incorrect here: M.foldrWithKey builds a Map Int String (via M.adjust (x:) onto []), so you only need to wrap each String once (e.g., fmap Letters/M.map Letters). The extra inner fmap tries to map Letters over the characters of the String and should not typecheck / would produce the wrong shape.
| reverseMapping = fmap (fmap Letters) . M.foldrWithKey | |
| reverseMapping = fmap Letters . M.foldrWithKey |
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.
If that problem were real, it would show up as a compiler error ...
Abstracts the
toMatchingandmatchCdOdSolutionfunctions to work with variable numbers of class and object diagrams, instead of being hard-coded to 2 CDs and 5 ODs.Changes Made
toMatching: Now takes a list of CD keys[Int]as a parameter instead of hard-coding[1, 2]. UsesM.toList mto iterate directly over key-value pairs, avoiding repeatedM.lookupcalls and theMaybewrapper for improved efficiency.matchCdOdSolution: Now derives CD keys from the instance'sdiagramsfield usingM.map (const []) (diagrams task)instead of hard-coding[(1, []), (2, [])].Call site: Updated
matchCdOdEvaluationto passM.keys $ diagrams task(the actual CD keys) totoMatching.These changes ensure the evaluation and solution logic correctly handles instances with different numbers of diagrams while improving performance by eliminating repeated map lookups.
Testing
The changes maintain clean, idiomatic Haskell code while properly abstracting over the number of diagrams and improving efficiency.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.