From 9419d0d25b77a35ba1607cb440c45d7799106c95 Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Wed, 24 Sep 2025 14:53:42 +1000 Subject: [PATCH] feat: improve pitch datatype with sub-types for notes and octaves --- Proj2.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Proj2.hs b/Proj2.hs index cac7a3a..2e23371 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -12,14 +12,25 @@ where 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 - { note :: Char, - octave :: Int + { note :: Note, + octave :: Octave } - deriving (Eq) + deriving (Eq, Ord) + +instance Show Octave where + show One = "1" + show Two = "2" + show Three = "3" instance Show Pitch where - show (Pitch note octave) = note : show octave + show (Pitch note octave) = show note ++ show octave toPitch :: String -> Maybe Pitch toPitch _ = Just (Pitch 'A' 1)