refactor: move matches function up to top of block to improve readability and inline functions in allChords for clarity
This commit is contained in:
parent
de3a7abafe
commit
1d86b09e0f
1 changed files with 10 additions and 18 deletions
28
Proj2.hs
28
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]
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue