
Hi David,
This helps, for sure. I wondered if any of the rich selection of
functions in Data.Map could be used, such as union. To perform a union
on two maps, their elements must have the same type. From this one
concludes that a type unifying Note's and PlayDirection's is
necessary, which is what you have done in Instruction.
On Thu, Aug 18, 2011 at 8:46 PM, David McBride
Maybe something like this:
instance Eq Loc where a == b = ... instance Ord Loc where compare a b = ...
data Instruction = InstrNote (Loc, Note) | InstrPD (Loc, PlayDirection)
write a function that will combine the notes and playdirections into one list of everything sequentially.
combineNotesDirs :: [(Loc,Note)] -> [(Loc,PlayDirection)] -> [Instruction] combineNotesDirs [] [] = [] combineNotesDirs [] (d:ds) = undefined --you can figure this out combineNotesDirs (n:ns) [] = undefined combineNotesDirs notes@(n:ns) dirs@(d:ds) | fst d <= fst n = InstrPD d : (zipNotesDirs notes ds) | otherwise = InstrNote n : (zipNotesDirs ns dirs)
Then loop over that and store them as a map. Traverse the list, keep track of the playdirection at each entry, and then accumulate the current direction and note at each note entry into a new map.
instructionlist2map :: [Instruction] -> Map Loc (Note, PlayDirection)
I'm sure this could be cleaned up a bit, but is that sort of what you were looking for?