I've added a new module to Bala for 'focused' shape and contents traversals.
It allows quite sophisticated operations like this:
retrograde :: Motif -> Motif
retrograde = rejoin pitchFocus . second reverse . separate pitchFocus
Here retrograde reverses just the pitch content of a motif, and not the rhythmic content. If you had a motif like this one (where qn is a quarter note and hn as a half note):
C qn, rest qn, D hn, E hn
The result would be
E qn, rest qn, D hn, C hn
The functions separate and rejoin work like decompose and reassemble from the paper 'The Essence of the Iterator Pattern' [Gibbons & Oliveira], but they have a special focusing mechanism that in this case extracts pitches as the content rather than the 'outer' datatype. In this case the outer datatype is a sum type that holds notes, chords and rests, etc. not all of which actually have a pitch attribute.