From 0c107d563e0bcf3a7ac750d7f778bc807569726a Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Wed, 17 Jan 2018 19:46:55 +0000 Subject: [PATCH] Apply hlint suggestions --- app/Main.hs | 4 ++-- src/Lib.hs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 1317b79..ab8f6ff 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -49,7 +49,7 @@ listLSystemsParser = infoOption (printList lsystems) splitOn :: Char -> String -> [String] splitOn c s = case dropWhile (== c) s of "" -> [] - s' -> w:(splitOn c s'') + s' -> w : splitOn c s'' where (w, s'') = break (== c) s' colorParser :: Parser Color @@ -60,7 +60,7 @@ colorParser = option (eitherReader readRGB) <> showDefault <> value white <> metavar "R,G,B") - where readRGB s = do + where readRGB s = case mapM readEitherSafe $ splitOn ',' s of Right (r:g:b:a:_) -> Right $ makeColorI r g b a Right (r:g:b:_) -> Right $ makeColorI r g b 255 diff --git a/src/Lib.hs b/src/Lib.hs index 03ed685..135e26e 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -45,10 +45,8 @@ iterateLSystem 0 lsystem = lsystem iterateLSystem n lsystem | n < 0 = iterateLSystem (-n) lsystem iterateLSystem n (LSystem na a ax r ang dist rep) = iterateLSystem (n-1) $ LSystem na a ax' r ang dist rep - where ax' = concat $ map f ax - f x = case lookup x r of - Just xs -> xs - Nothing -> [x] + where ax' = concatMap f ax + f x = fromMaybe [x] (lookup x r) -- | Generate a set of instructions from an L-system instructions :: Eq a => LSystem a -> [Instruction] @@ -71,7 +69,7 @@ turtle angle distance = go 90 (Line [(0,0)]) (Pictures []) [] TurnLeft -> go (theta - angle) (Line path) (Pictures ps) stack xs Push -> go theta (Line path) (Pictures ps) ((head path, theta):stack) xs Pop -> let (pos, theta'):t = stack in - go theta' (Line [pos]) (Pictures ((Line path):ps)) t xs + go theta' (Line [pos]) (Pictures (Line path : ps)) t xs Stay -> go theta (Line path) (Pictures ps) stack xs where (px, py) = head path