From 1d86b09e0f6765346692fcfd4f724f6ae4d4a4de Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:34:27 +1000 Subject: [PATCH] refactor: move matches function up to top of block to improve readability and inline functions in allChords for clarity --- Proj2.hs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Proj2.hs b/Proj2.hs index 9c67d4a..7631262 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -162,6 +162,11 @@ nextGuess (prevGuess, chord : chords) _ = (chord, chords) -- ==== 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 = @@ -174,22 +179,9 @@ allChords = p1 < p2, p2 < p3 ] - -allPitches :: [Pitch] -allPitches = - [ Pitch note octave - | note <- allNotes, - octave <- allOctaves - ] - -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 + allPitches = + [ Pitch note octave + | note <- [minBound .. maxBound], + octave <- [minBound .. maxBound] + ]