refactor: move matches function up to top of block to improve readability and inline functions in allChords for clarity

This commit is contained in:
wi11-holdsworth 2025-10-01 14:34:27 +10:00
parent de3a7abafe
commit 1d86b09e0f

View file

@ -162,6 +162,11 @@ nextGuess (prevGuess, chord : chords) _ = (chord, chords)
-- ==== HELPER FUNCTIONS ====================================================== -- ==== HELPER FUNCTIONS ======================================================
matches :: (Eq a, Show a) => [a] -> [a] -> Int
matches xs ys = maximum permutationMatches
where
permutationMatches = map (pairwiseMatches xs) (permutations ys)
pairwiseMatches xs ys = length $ filter (uncurry (==)) $ zip xs ys
allChords :: [[Pitch]] allChords :: [[Pitch]]
allChords = allChords =
@ -174,22 +179,9 @@ allChords =
p1 < p2, p1 < p2,
p2 < p3 p2 < p3
] ]
where
allPitches :: [Pitch]
allPitches = allPitches =
[ Pitch note octave [ Pitch note octave
| note <- allNotes, | note <- [minBound .. maxBound],
octave <- allOctaves octave <- [minBound .. maxBound]
] ]
allOctaves :: [Octave]
allOctaves = [minBound .. maxBound]
allNotes :: [Note]
allNotes = [minBound .. maxBound]
matches :: (Eq a, Show a) => [a] -> [a] -> Int
matches xs ys = maximum permutationMatches
where
permutationMatches = map (pairwiseMatches xs) (permutations ys)
pairwiseMatches xs ys = length $ filter (uncurry (==)) $ zip xs ys