A musical composition can arrange notes and pauses in succession. A melody is a sequence of notes; sequences can also contain other sequences or groups, such as chords played one after another. This requires a recursive structure rather than a flat collection. section 11.1
Figure 11.1 A melody is a sequence of notes
A melody illustrates the simplest case: notes ordered to play one after another. section 11.1
In Haskell, `Sequence [NoteStructure a]` represents ordered composition elements alongside `Note`, `Pause`, and `Group`. Keeping them under `NoteStructure` lets composition operators combine the same overall kind of value, while the type parameter still makes ordinary structures homogeneous. section 11.1
A sequencing operator can hide both the `Sequence` constructor and its backing list. When either operand is already a sequence, it adds the other element or joins the two sequences; otherwise, it creates a new two-element sequence. This flattening avoids unnecessary nested sequences. section 11.3.2
Listing 11.9 An infix operator to construct sequences of compositions
(<~>) :: NoteStructure -> NoteStructure -> NoteStructure (<~>) (Sequence xs) (Sequence ys) = Sequence $ xs ++ ys #1 (<~>) (Sequence xs) x = Sequence $ xs ++ [x] #2 (<~>) x (Sequence xs) = Sequence $ x : xs #2 (<~>) a b = Sequence [a, b] #3 infixr 3 <~>
The `<~>` operator merges existing sequences or constructs one from two composition elements, then assigns right-associative precedence. section 11.3.2
Sequencing three notes
`c 4 .| wn <~> e 4 .| wn <~> g 4 .| wn` produces one `Sequence` containing the C, E, and G notes in order. The same DSL also has `<:>` for groups, with `<~>` given higher precedence. section 11.3.2
Sequential data also appears as `Seq` from `Data.Sequence` when output must grow at its end. For a `WriterT` log, appending to a plain list repeatedly can cause quadratic work; `Seq` supports constant-time end appends and avoids that growth problem. section 15.1.2





















