liveBook · Manning

Chromatic note name

As explained in Learn Haskell by Example

A chromatic note name identifies one of the twelve semitone-spaced note names within an octave.

A chromatic note name identifies one of twelve semitone-spaced names within an octave, such as A, As, B, C, or Cs. It separates a note’s name from its octave number, making pitch values easier to represent and pattern-match. section 10.4.1

Listing 10.12 A class for types that can be converted to a frequency
{-# LANGUAGE TypeSynonymInstances #-}
module Composition.Pitch where

class Pitchable a where      #1
  toFrequency :: a -> Hz

instance Pitchable Hz where
  toFrequency = id         #2

Use the accompanying pitch-conversion design to connect chromatic notes with frequency calculations. section 10.4.1

A practical Haskell representation separates the two parts:

  • ChromaticName enumerates the twelve names and derives Show and Eq. section 10.4.1
  • Chromatic pairs a ChromaticName with a nonnegative Natural octave number. section 10.4.1
  • Helper functions such as a, as, and gs construct notes by supplying only the octave. section 10.4.1
  • Conversion assigns each name an offset from A4 and combines it with the octave displacement. section 10.4.1

Converting a note to frequency

Evaluating toFrequency (a 4) produces 440.0, while a 5 produces 880.0. Notes can then form a melody whose frequencies are written to a WAV file. section 10.4.1

How Learn Haskell by Example covers it

How deep it goes
Defines names, octave pairing, constructors, and A4-based conversion, stopping short of broader notation systems.
Examples
Uses named values such as A4 and C2, helper constructors, frequency evaluations, and a generated melody.
What it assumes
Assumes familiarity with semitones and octaves while teaching the Haskell data representation from the note model onward.
What you can do after
Builds a typed chromatic-note representation and converts its values into playable frequencies.
How it connects
Connects chromatic note names with semitones, octaves, frequencies, and pitch type classes.

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.