I encountered a small aesthetic issue in my music project and it has been bugging me for some time.
I have a type data Key = C | D | ...
and I can construct a Scale
from a Key
and a Mode
. The Mode
distinguishes between e.g. a major and a minor scale.
I can define the Mode
type as a function from Key
to Scale
. In that case the modes will have lowercase names (which is fine) and I can get a Scale like this
aScale = major C
But musicians don't talk like this. They refer to this scale as the C major scale, not the major C scale.
What I want
Ideally I'd want to write
aScale = C major
Is this possible at all?
What I tried
I can make Key
a function that constructs a Scale
from a Mode
, so I can write
aScale = c Major
But I cannot confine Keys to constructing Scales. They are needed for other things as well (e.g. constructing chords). Also Key
should be an instance of Show
.
I can put the Mode
after the Key
when I use an extra function (or value constructor):
aScale = scale C major
with scale :: Key -> Mode -> Scale
But the extra word scale looks noisy and contrary to its name, scale
isn't really concerned with scales. The intelligent part is in major
, scale
is really just flip ($)
.
Using a newtype Mode = Major | Minor ...
doesn't really change much, except scale
needs to be more intelligent:
aScale = scale C Major
C major (or the key of C) is a major scale based on C, consisting of the pitches C, D, E, F, G, A, and B. C major is one of the most common keys used in music. Its key signature has no flats and no sharps. Its relative minor is A minor and its parallel minor is C minor.
The defining difference between C major and A minor is that the tonal center of C major is C and the tonal center of A minor is A. This means that, in C major, chords and melodies will tend to return to rest on the C note, whereas in A minor they will tend to resolve and rest on the A note.
Yes, if a song is purely diatonic (using only the notes from its scale, with no extra # or b. It can be played in any key out of the 12.
For the C major chord, the root note is C, the major 3rd is E, and the perfect 5th is G.
Solution 1:
Use this
data Mode = Major | Minor data Scale = C Mode | D Mode | E Mode | F Mode | G Mode | A Mode | B Mode
Now you can write (with capital C and capital M)
aScale = C Major
Solution 2a:
This is also possible
data Mode = Major | Minor data Key = C | D | E | F | G | A | B data Scale = Scale Key Mode
Now you write
aScale = Scale C Major
Solution 2b:
This is also possible
data Mode = Major | Minor data Key = C | D | E | F | G | A | B type Scale = (Key, Mode)
Now you write
aScale = (C, Major)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With