While.hs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
boolExpr:: Parser BExp
boolExpr = buildExpressionParser boolOperators relExpr

relExpr :: Parser BExp
relExpr = do{ arg1 <- aritExpr
            ; op <- choice [string "=", try (string "<>"), try (string "<="), string "<", try (string ">="), string ">"]
            ; arg2 <- aritExpr
            ; return (RelOp op arg1 arg2)
            }

aritExpr :: Parser AExp
aritExpr = buildExpressionParser aritOperators simpleArit

-- Everything mapping bools to bools
boolOperators =
    [ [ prefix "not"]
    , [ opbb "and" AssocRight ] -- right for shortcircuit
    , [ opbb "or" AssocRight ] -- right for shortcircuit
    ]
    where
      opbb name assoc   = Infix (do{ reservedOp name
                                   ; return (\x y -> BOp name x y) 
                                   }) assoc
      prefix name       = Prefix  (do{ reservedOp name
                                  ; return (\x -> BUnOp name x)
                                  })                                      

-- Everything mapping pairs of ints to ints
aritOperators =
    [ [ op "*"  AssocLeft, op "/"  AssocLeft ]
    , [ op "+"  AssocLeft, op "-"  AssocLeft ]
    , [ op "&" AssocRight ] -- bitwise and delivering an int
    , [ op "|" AssocRight ] -- bitwise or delivering an int
    ]
    where
      op name assoc   = Infix (do{ reservedOp name
                                  ; return (\x y -> AOp name x y) 
                                  }) assoc


simpleArit = choice [ intLiteral
                    , parens aritExpr
                    , variable
                    ]
21:7: Error: Eta reduce
Found:
opbb name assoc
= Infix
(do reservedOp name
return (\ x y -> BOp name x y))
assoc
Why not:
opbb name
= Infix
(do reservedOp name
return (\ x y -> BOp name x y))
22:46: Warning: Avoid lambda
Found:
\ x y -> BOp name x y
Why not:
BOp name
25:45: Warning: Avoid lambda
Found:
\ x -> BUnOp name x
Why not:
BUnOp name
36:7: Error: Eta reduce
Found:
op name assoc
= Infix
(do reservedOp name
return (\ x y -> AOp name x y))
assoc
Why not:
op name
= Infix
(do reservedOp name
return (\ x y -> AOp name x y))
37:45: Warning: Avoid lambda
Found:
\ x y -> AOp name x y
Why not:
AOp name