Skip to content

Commit 0ff3fbd

Browse files
jrp2014Adam Wespiser
authored andcommitted
apply hlint hints
1 parent a4ccbc7 commit 0ff3fbd

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

src/Eval.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import System.Directory ( doesFileExist )
3535
import Text.Parsec ( ParseError )
3636

3737
import Control.Monad.Reader
38-
( MonadIO(liftIO), MonadReader(local, ask), ReaderT(runReaderT) )
38+
( asks, MonadIO(liftIO), MonadReader(local, ask), ReaderT(runReaderT) )
3939
import Control.Exception
4040
( try, throw, Exception(fromException), SomeException )
4141

@@ -76,7 +76,7 @@ lineToEvalForm input = either (throw . PError . show ) eval $ readExpr input
7676

7777

7878
evalFile :: FilePath -> T.Text -> IO () --program file
79-
evalFile filePath fileExpr = (runASTinEnv basicEnv $ fileToEvalForm filePath fileExpr) >>= print
79+
evalFile filePath fileExpr = runASTinEnv basicEnv (fileToEvalForm filePath fileExpr) >>= print
8080

8181
fileToEvalForm :: FilePath -> T.Text -> Eval LispVal
8282
fileToEvalForm filePath input = either (throw . PError . show ) evalBody $ readExprFile filePath input
@@ -198,8 +198,7 @@ eval (List (Atom "let":_) ) = throw $ BadSpecialForm "let function expects list
198198

199199

200200
eval (List [Atom "lambda", List params, expr]) = do
201-
ctx <- ask
202-
return $ Lambda (IFunc $ applyLambda expr params) ctx
201+
asks (Lambda (IFunc $ applyLambda expr params))
203202
eval (List (Atom "lambda":_) ) = throw $ BadSpecialForm "lambda function expects list of parameters and S-Expression body\n(lambda <params> <s-expr>)"
204203

205204

@@ -215,12 +214,12 @@ eval all@(List [Atom "cdr", arg@(List (x:xs))]) =
215214

216215

217216
eval all@(List [Atom "car", List [Atom "quote", List (x:xs)]]) =
218-
return $ x
217+
return x
219218
eval all@(List [Atom "car", arg@(List (x:xs))]) =
220219
case x of
221220
Atom _ -> do val <- eval arg
222221
eval $ List [Atom "car", val]
223-
_ -> return $ x
222+
_ -> return x
224223

225224

226225
eval all@(List ((:) x xs)) = do

src/Parser.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Text.Parsec.Text ( Parser )
2828
import qualified Text.Parsec.Token as Tok
2929
import qualified Text.Parsec.Language as Lang
3030

31+
import Data.Functor (($>))
3132
import Data.Functor.Identity (Identity)
3233
import qualified Data.Text as T
3334
import Data.Char (digitToInt)
@@ -84,8 +85,8 @@ decimal = Tok.decimal lexer
8485
-- | Parse a sign, return either @id@ or @negate@ based on the sign parsed.
8586
-- Copied from Text.Parsec.Token
8687
sign :: Parser (Integer -> Integer)
87-
sign = char '-' *> return negate
88-
<|> char '+' *> return id
88+
sign = char '-' $> negate
89+
<|> char '+' $> id
8990
<|> return id
9091

9192
intRadix :: Radix -> Parser Integer
@@ -95,12 +96,12 @@ textLiteral :: Parser T.Text
9596
textLiteral = T.pack <$> Tok.stringLiteral lexer
9697

9798
nil :: Parser ()
98-
nil = try ((char '\'') *> string "()") *> return () <?> "nil"
99+
nil = try (char '\'' *> string "()") *> return () <?> "nil"
99100

100101
hashVal :: Parser LispVal
101102
hashVal = lexeme $ char '#'
102-
*> (char 't' *> return (Bool True)
103-
<|> char 'f' *> return (Bool False)
103+
*> (char 't' $> Bool True
104+
<|> char 'f' $> Bool False
104105
<|> char 'b' *> (Number <$> intRadix (2, oneOf "01"))
105106
<|> char 'o' *> (Number <$> intRadix (8, octDigit))
106107
<|> char 'd' *> (Number <$> intRadix (10, digit))

src/Prim.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import LispVal
88
LispVal(Atom, Fun, Number, String, Bool, Nil, List),
99
Eval )
1010

11+
import Data.Functor ((<&>))
1112
import Data.Text as T ( Text, concat, pack, unpack )
1213
import Data.Text.IO as TIO ( hGetContents, hPutStr )
1314
import System.Directory ( doesFileExist )
@@ -45,11 +46,11 @@ primEnv = [
4546
, ("bl-eq?", mkF $ binop $ eqOp (==))
4647
, ("and" , mkF $ binopFold (eqOp (&&)) (Bool True))
4748
, ("or" , mkF $ binopFold (eqOp (||)) (Bool False))
48-
, ("not" , mkF $ unop $ notOp)
49-
, ("cons" , mkF $ Prim.cons)
50-
, ("cdr" , mkF $ Prim.cdr)
51-
, ("car" , mkF $ Prim.car)
52-
, ("quote" , mkF $ quote)
49+
, ("not" , mkF $ unop notOp)
50+
, ("cons" , mkF Prim.cons)
51+
, ("cdr" , mkF Prim.cdr)
52+
, ("car" , mkF Prim.car)
53+
, ("quote" , mkF quote)
5354
, ("file?" , mkF $ unop fileExists)
5455
, ("slurp" , mkF $ unop slurp)
5556
, ("wslurp", mkF $ unop wSlurp)
@@ -90,7 +91,7 @@ readTextFile :: T.Text -> Handle -> IO LispVal
9091
readTextFile fileName handle = do
9192
exists <- doesFileExist $ T.unpack fileName
9293
if exists
93-
then (TIO.hGetContents handle) >>= (return . String)
94+
then TIO.hGetContents handle <&> String
9495
else throw $ IOError $ T.concat [" file does not exits: ", fileName]
9596

9697
put :: LispVal -> LispVal -> Eval LispVal
@@ -106,7 +107,7 @@ putTextFile :: T.Text -> T.Text -> Handle -> IO LispVal
106107
putTextFile fileName msg handle = do
107108
canWrite <- hIsWritable handle
108109
if canWrite
109-
then (TIO.hPutStr handle msg) >> (return $ String msg)
110+
then TIO.hPutStr handle msg >> return (String msg)
110111
else throw $ IOError $ T.concat [" file does not exits: ", fileName]
111112

112113
binopFold :: Binary -> LispVal -> [LispVal] -> Eval LispVal

test-hs/Golden/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ tastyGoldenRun testName testFile correct =
5252
tastyGoldenFail :: TestName -> T.Text -> FilePath -> TestTree
5353
tastyGoldenFail testName testFile correct =
5454
goldenVsString testName correct $
55-
(safeExec $ evalTextTest "lib/stdlib.scm" testFile) <&>
55+
safeExec (evalTextTest "lib/stdlib.scm" testFile) <&>
5656
either C.pack (C.pack . show)
5757

5858
evalTextTest :: T.Text -> T.Text -> IO LispVal --REPL

test-hs/Spec/Main.hs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,70 +21,70 @@ main = do
2121
hspec $ describe "src/Parser.hs" $ do
2222

2323
it "Atom" $
24-
readExpr "bb-8?" `shouldBe` (Right $ Atom "bb-8?")
24+
readExpr "bb-8?" `shouldBe` Right (Atom "bb-8?")
2525

2626
it "Num Negative" $
27-
readExpr "-2187" `shouldBe` (Right $ Number (-2187))
27+
readExpr "-2187" `shouldBe` Right (Number (-2187))
2828

2929
it "Num Positive" $
30-
readExpr "112233" `shouldBe` (Right $ Number 112233)
30+
readExpr "112233" `shouldBe` Right (Number 112233)
3131

3232
it "Num Positive with Sign" $
33-
readExpr "+12345" `shouldBe` (Right $ Number 12345)
33+
readExpr "+12345" `shouldBe` Right (Number 12345)
3434

3535
it "String" $
36-
readExpr "\"Gen L Organa\"" `shouldBe` (Right $ String "Gen L Organa")
36+
readExpr "\"Gen L Organa\"" `shouldBe` Right (String "Gen L Organa")
3737

3838
it "Bool True" $
39-
readExpr "#t" `shouldBe` (Right $ Bool True)
39+
readExpr "#t" `shouldBe` Right (Bool True)
4040

4141
it "Bool False" $
42-
readExpr "#f" `shouldBe` (Right $ Bool False)
42+
readExpr "#f" `shouldBe` Right (Bool False)
4343

4444
it "Nil" $
45-
readExpr "'()" `shouldBe` (Right $ Nil)
45+
readExpr "'()" `shouldBe` Right Nil
4646

4747
it "S-Expr: homogenous list" $
4848
readExpr "(2 1 87)" `shouldBe`
49-
(Right $ List [Number 2, Number 1,Number 87])
49+
Right (List [Number 2, Number 1,Number 87])
5050

5151
it "S-Expr: homogenous list quoted" $
5252
readExpr "'(2 1 87)" `shouldBe`
53-
(Right $ List [Atom "quote",List [Number 2, Number 1,Number 87]])
53+
Right (List [Atom "quote",List [Number 2, Number 1,Number 87]])
5454

5555
it "S-Expr: heterogenous list" $
5656
readExpr "(stromTrooper \"Fn\" 2 1 87)" `shouldBe`
57-
(Right $ List [Atom "stromTrooper", String "Fn", Number 2, Number 1,Number 87])
57+
Right (List [Atom "stromTrooper", String "Fn", Number 2, Number 1,Number 87])
5858

5959
it "S-Expr: heterogenous list quoted" $
6060
readExpr "'(stromTrooper \"Fn\" 2 1 87)" `shouldBe`
61-
(Right $ List [Atom "quote", List [Atom "stromTrooper", String "Fn", Number 2, Number 1,Number 87]])
61+
Right (List [Atom "quote", List [Atom "stromTrooper", String "Fn", Number 2, Number 1,Number 87]])
6262

6363
it "S-Expr: single negative" $
64-
readExpr "(-42)" `shouldBe` (Right $ List [Number (-42)])
64+
readExpr "(-42)" `shouldBe` Right (List [Number (-42)])
6565

6666
it "S-Expr: (- num)" $
67-
readExpr "(- 42)" `shouldBe` (Right $ List [Atom "-", Number 42])
67+
readExpr "(- 42)" `shouldBe` Right (List [Atom "-", Number 42])
6868

6969
it "S-Expr: prim call: numbers" $
7070
readExpr "(+ 1 2)" `shouldBe`
71-
(Right $ List [Atom "+", Number 1, Number 2])
71+
Right (List [Atom "+", Number 1, Number 2])
7272

7373
it "S-Expr: prim call: neg nums" $
7474
readExpr "(- -42 -42)" `shouldBe`
75-
(Right $ List [Atom "-", Number (-42), Number (-42)])
75+
Right (List [Atom "-", Number (-42), Number (-42)])
7676

7777
it "S-Expr: prim call: atoms" $
7878
readExpr "(- rogue squadron)" `shouldBe`
79-
(Right $ List [Atom "-", Atom "rogue", Atom "squadron"])
79+
Right (List [Atom "-", Atom "rogue", Atom "squadron"])
8080

8181
it "S-Expr: nested list" $
8282
readExpr "(lambda (x x) (+ x x))" `shouldBe`
83-
(Right $ List [Atom "lambda", List [Atom "x", Atom "x"], List [Atom "+", Atom "x", Atom "x"]])
83+
Right (List [Atom "lambda", List [Atom "x", Atom "x"], List [Atom "+", Atom "x", Atom "x"]])
8484
it "Comment: end-of/single line" $
85-
readExpr ";skip\nartoodetoo ;extra will throw\n;skip" `shouldBe` (Right $ Atom "artoodetoo")
85+
readExpr ";skip\nartoodetoo ;extra will throw\n;skip" `shouldBe` Right (Atom "artoodetoo")
8686
it "Comment: multi-line line" $
87-
readExpr "{-Han\nShot\nFirst\n-} (c3 {- these are not the droids you're looking for-} po)\n {-Jar Jar Binks =?= Sith Lord -}" `shouldBe` (Right $ List [Atom "c3",Atom "po"])
87+
readExpr "{-Han\nShot\nFirst\n-} (c3 {- these are not the droids you're looking for-} po)\n {-Jar Jar Binks =?= Sith Lord -}" `shouldBe` Right (List [Atom "c3",Atom "po"])
8888

8989
hspec $ describe "src/Eval.hs" $ do
9090
wStd "test/add.scm" $ Number 3
@@ -126,7 +126,7 @@ wStd = runExpr (Just "test/stdlib_mod.scm")
126126
tExpr :: T.Text -> T.Text -> LispVal -> SpecWith ()
127127
tExpr note expr val =
128128
it (T.unpack note) $ evalVal `shouldBe` val
129-
where evalVal = (unsafePerformIO $ runASTinEnv basicEnv $ fileToEvalForm "" expr)
129+
where evalVal = unsafePerformIO $ runASTinEnv basicEnv $ fileToEvalForm "" expr
130130

131131

132132
runExpr :: Maybe T.Text -> T.Text -> LispVal -> SpecWith ()

0 commit comments

Comments
 (0)