feat: improve pitch datatype with sub-types for notes and octaves

This commit is contained in:
wi11-holdsworth 2025-09-24 14:53:42 +10:00
parent 6f600ff149
commit 9419d0d25b

View file

@ -12,14 +12,25 @@ where
type GameState = () type GameState = ()
data Note = A | B | C | D | E | F | G
deriving (Eq, Show, Ord)
data Octave = One | Two | Three
deriving (Eq, Ord)
data Pitch = Pitch data Pitch = Pitch
{ note :: Char, { note :: Note,
octave :: Int octave :: Octave
} }
deriving (Eq) deriving (Eq, Ord)
instance Show Octave where
show One = "1"
show Two = "2"
show Three = "3"
instance Show Pitch where instance Show Pitch where
show (Pitch note octave) = note : show octave show (Pitch note octave) = show note ++ show octave
toPitch :: String -> Maybe Pitch toPitch :: String -> Maybe Pitch
toPitch _ = Just (Pitch 'A' 1) toPitch _ = Just (Pitch 'A' 1)