style: format code
This commit is contained in:
parent
f49eba9676
commit
3654485f23
2 changed files with 23 additions and 22 deletions
6
Main.hs
6
Main.hs
|
|
@ -10,14 +10,12 @@ import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Proj2
|
import Proj2
|
||||||
|
|
||||||
|
|
||||||
-- | Guess the given target, counting and showing the guesses.
|
-- | Guess the given target, counting and showing the guesses.
|
||||||
guessTest :: [Pitch] -> IO ()
|
guessTest :: [Pitch] -> IO ()
|
||||||
guessTest target = do
|
guessTest target = do
|
||||||
let (guess, other) = initialGuess
|
let (guess, other) = initialGuess
|
||||||
loop target guess other 1
|
loop target guess other 1
|
||||||
|
|
||||||
|
|
||||||
-- | Given a target and guess and a guess number, continue guessing
|
-- | Given a target and guess and a guess number, continue guessing
|
||||||
-- until the right target is guessed.
|
-- until the right target is guessed.
|
||||||
loop :: [Pitch] -> [Pitch] -> GameState -> Int -> IO ()
|
loop :: [Pitch] -> [Pitch] -> GameState -> Int -> IO ()
|
||||||
|
|
@ -32,12 +30,10 @@ loop target guess other guesses = do
|
||||||
let (guess', other') = nextGuess (guess, other) answer
|
let (guess', other') = nextGuess (guess, other) answer
|
||||||
loop target guess' other' (guesses + 1)
|
loop target guess' other' (guesses + 1)
|
||||||
|
|
||||||
|
|
||||||
-- | Parse a string containing a number of space-separated pitches to produce
|
-- | Parse a string containing a number of space-separated pitches to produce
|
||||||
-- a list of pitches. Error if any of the pitches can't be parsed.
|
-- a list of pitches. Error if any of the pitches can't be parsed.
|
||||||
toChord :: String -> [Pitch]
|
toChord :: String -> [Pitch]
|
||||||
toChord = (fromJust . mapM toPitch . words)
|
toChord = fromJust . mapM toPitch . words
|
||||||
|
|
||||||
|
|
||||||
-- | Prompt for a target and use guessTest to try to guess it.
|
-- | Prompt for a target and use guessTest to try to guess it.
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
|
|
||||||
27
Proj2.hs
27
Proj2.hs
|
|
@ -1,20 +1,25 @@
|
||||||
--Implement your solution here
|
--
|
||||||
--SEE THE PROJECT CODING GUIDELINES ON THE LMS FOR DETAILS OF
|
|
||||||
--THE CRITERIA THAT WILL BE EMPLOYED IN ASSESSING YOUR CODE.
|
|
||||||
--Please DELETE THIS WHOLE COMMENT, and write your own.
|
|
||||||
|
|
||||||
module Proj2 (Pitch, toPitch, feedback,
|
module Proj2
|
||||||
GameState, initialGuess, nextGuess) where
|
( Pitch,
|
||||||
|
toPitch,
|
||||||
|
feedback,
|
||||||
|
GameState,
|
||||||
|
initialGuess,
|
||||||
|
nextGuess,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
type GameState = ()
|
type GameState = ()
|
||||||
|
|
||||||
data Pitch = Pitch { note :: Char
|
data Pitch = Pitch
|
||||||
, octave :: Int
|
{ note :: Char,
|
||||||
} deriving (Eq)
|
octave :: Int
|
||||||
|
}
|
||||||
|
deriving (Eq)
|
||||||
|
|
||||||
instance Show Pitch where
|
instance Show Pitch where
|
||||||
show (Pitch note octave) = [note] ++ show octave
|
show (Pitch note octave) = note : show octave
|
||||||
|
|
||||||
|
|
||||||
toPitch :: String -> Maybe Pitch
|
toPitch :: String -> Maybe Pitch
|
||||||
toPitch _ = Just (Pitch 'A' 1)
|
toPitch _ = Just (Pitch 'A' 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue