<div dir="ltr">I have a Haskell program that computes music compositions. A composition consists of sounds that happen at locations. A location is data type Loc. At each location is a list of chords. A chord is data type Chord. Each chord contains some chord-specific data and a list of notes. A note is data type Note. <div><br></div><div>So we have</div><div><br></div><div>data Note = Note ...</div><div>data Chord = Chord ChordSpecificData [Note]</div><div>type Composition = Map Loc [Chord]</div><div><br></div><div>I would like to write a few different functions that operate over all the notes.</div><div><br></div><div>The following function breaks out all the notes, tupling them with the associated Locs and Chords:</div><div>compositionToList :: Composition -> [(Loc,Chord,Note)]</div><div><br></div><div>The following function transforms Notes, keeping only the Just results. If a Chord gets all its notes eliminated, that Chord is removed. If a Loc has all its Chords removed, that Loc is removed from the Map.</div><div>mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition </div><div>   -> Composition</div><div><br></div><div>Any advice for concise code appreciated.</div><div>Dennis</div><div><br></div><div><br></div><div>What's a concise way of doing this?</div><div><br></div><div>Another useful function would be used for mapping</div><div><br></div><div>Dennis</div><div><br></div></div>