feat: improve pitch datatype with sub-types for notes and octaves
This commit is contained in:
parent
6f600ff149
commit
9419d0d25b
1 changed files with 15 additions and 4 deletions
19
Proj2.hs
19
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue