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
24
Proj2.hs
24
Proj2.hs
|
|
@ -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
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue