From 334616392b5887d2d17c9a0b118e6002a74e4bae Mon Sep 17 00:00:00 2001 From: William Carroll Date: Sat, 15 Aug 2020 18:30:42 +0100 Subject: Set -Wall and cleanup warnings I should have done this from the start. --- assessments/dotted-squares/.ghci | 1 + assessments/dotted-squares/Main.hs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 assessments/dotted-squares/.ghci (limited to 'assessments') diff --git a/assessments/dotted-squares/.ghci b/assessments/dotted-squares/.ghci new file mode 100644 index 000000000000..b100af4432c5 --- /dev/null +++ b/assessments/dotted-squares/.ghci @@ -0,0 +1 @@ +:set -Wall diff --git a/assessments/dotted-squares/Main.hs b/assessments/dotted-squares/Main.hs index 0e166bad2718..44f91e2b2311 100644 --- a/assessments/dotted-squares/Main.hs +++ b/assessments/dotted-squares/Main.hs @@ -78,8 +78,8 @@ digit = satisfy (\c -> c >= '0' && c <= '9') int :: ReadP Int int = read <$> many1 digit -line :: ReadP String -line = manyTill get (char '\n') +inputLine :: ReadP String +inputLine = manyTill get (char '\n') direction :: ReadP Direction direction = do @@ -89,6 +89,7 @@ direction = do 'R' -> pure DirRight 'U' -> pure DirUp 'D' -> pure DirDown + _ -> fail $ "Unexpected direction: " ++ show c validMove :: Int -> Int -> ReadP Line validMove w h = do @@ -97,7 +98,7 @@ validMove w h = do y <- int skipSpaces dir <- direction - char '\n' + _ <- char '\n' if x >= 0 && x <= w && y >= 0 && y <= h then do let beg = Point x y pure $ mkLine beg (shiftPoint dir beg) @@ -106,9 +107,9 @@ validMove w h = do game :: ReadP Game game = do - w <- read <$> line :: ReadP Int - h <- read <$> line :: ReadP Int - locs <- read <$> line :: ReadP Int + w <- read <$> inputLine + h <- read <$> inputLine + locs <- read <$> inputLine moves <- count locs (validMove w h) eof pure $ Game mempty moves @@ -157,7 +158,7 @@ doRotateLine Vertical End CW (Line _ end) = mkLineDir' end DirLeft doRotateLine Vertical End CCW (Line _ end) = mkLineDir' end DirRight classifyOrientation :: Line -> Orientation -classifyOrientation (Line (Point x1 y1) (Point x2 y2)) = +classifyOrientation (Line (Point _ y1) (Point _ y2)) = if y1 == y2 then Horizontal else Vertical closesAnySquare :: HS.HashSet Line -> Line -> Bool @@ -211,7 +212,7 @@ main = do input <- readFile "game.txt" case parseInput input of Nothing -> putStrLn "invalid" - Just game -> - case scoreGame Player1 game mempty of + Just parsedGame -> + case scoreGame Player1 parsedGame mempty of Nothing -> putStrLn "invalid" Just score -> print score -- cgit 1.4.1