on master help sign in
Remove some needless bracketing from if...then...else
commit7df6265e249f100cbfc84b1c13ba9817b9ad396a authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateMon 16 Jan 2012, 10:10 (15 years ago) parent33bf2bd
6 files changed+22−18
lib/prelude.idr+8−7 src/Idris/Parser.hs+1−1 tutorial/examples/interp.idr+3−2 tutorial/interp.tex+6−6 tutorial/syntax.tex+3−1 tutorial/typesfuns.tex+1−1
lib/prelude.idr+8−7
@@ -155,8 +155,8 @@ ceiling x = prim__floatCeil x
155155---- Ranges
156156
157157count : Num a => a -> a -> a -> List a
158−count a inc b = if (a <= b) then (a :: count (a + inc) inc b)
159− else []
158+count a inc b = if a <= b then a :: count (a + inc) inc b
159+ else []
160160
161161syntax "[" [start] ".." [end] "]"
162162 = count start 1 end
@@ -250,7 +250,9 @@ validFile (FHandle h) = do x <- nullPtr h
250250
251251while : |(test : IO Bool) -> |(body : IO ()) -> IO ()
252252while t b = do v <- t
253− if v then (do { b; while t b }) else return ()
253+ if v then do b
254+ while t b
255+ else return ()
254256
255257
256258readFile : String -> IO String
@@ -262,8 +264,7 @@ readFile fn = do h <- openFile fn Read
262264 readFile' : File -> String -> IO String
263265 readFile' h contents =
264266 do x <- feof h
265− if (not x) then (do l <- fread h
266− readFile' h (contents ++ l)
267− )
268− else (return contents)
267+ if not x then do l <- fread h
268+ readFile' h (contents ++ l)
269+ else return contents
269270
src/Idris/Parser.hs+1−1
@@ -536,7 +536,7 @@ pExtensions syn rules = choice (map (\x -> try (pExt syn x)) (filter valid rules
536536pExt :: SyntaxInfo -> Syntax -> IParser PTerm
537537pExt syn (Rule (s:ssym) ptm _)
538538 = do s1 <- pSymbol pSimpleExpr s
539− smap <- mapM (pSymbol pExpr') ssym
539+ smap <- mapM (pSymbol pExpr) ssym
540540 let ns = mapMaybe id (s1:smap)
541541 return (update ns ptm) -- updated with smap
542542 where
tutorial/examples/interp.idr+3−2
@@ -34,9 +34,10 @@ using (G : Vect Ty n)
3434 interp env (Var i) = lookup i env
3535 interp env (Val x) = x
3636 interp env (Lam sc) = \x => interp (x :: env) sc
37− interp env (App f s) = (interp env f) (interp env s)
37+ interp env (App f s) = interp env f (interp env s)
3838 interp env (Op op x y) = op (interp env x) (interp env y)
39− interp env (If x t e) = if (interp env x) then (interp env t) else (interp env e)
39+ interp env (If x t e) = if interp env x then interp env t
40+ else interp env e
4041
4142 eId : Expr G (TyFun TyInt TyInt)
4243 eId = Lam (Var stop)
tutorial/interp.tex+6−6
@@ -196,10 +196,10 @@ interp : Env G -> Expr G t -> interpTy t
196196interp env (Var i) = lookup i env
197197interp env (Val x) = x
198198interp env (Lam sc) = \x => interp (x :: env) sc
199−interp env (App f s) = (interp env f) (interp env s)
199+interp env (App f s) = interp env f (interp env s)
200200interp env (Op op x y) = op (interp env x) (interp env y)
201−interp env (If x t e) = if (interp env x) then (interp env t)
202− else (interp env e)
201+interp env (If x t e) = if interp env x then interp env t
202+ else interp env e
203203
204204\end{SaveVerbatim}
205205\codefig{interpdef}{Intepreter definition}
@@ -255,7 +255,7 @@ type:
255255
256256\begin{SaveVerbatim}{appinterp}
257257
258−interp env (App f s) = (interp env f) (interp env s)
258+interp env (App f s) = interp env f (interp env s)
259259
260260\end{SaveVerbatim}
261261\useverb{appinterp}
@@ -269,8 +269,8 @@ directly.
269269\begin{SaveVerbatim}{opinterp}
270270
271271interp env (Op op x y) = op (interp env x) (interp env y)
272−interp env (If x t e) = if (interp env x) then (interp env t)
273− else (interp env e)
272+interp env (If x t e) = if interp env x then interp env t
273+ else interp env e
274274
275275\end{SaveVerbatim}
276276\useverb{opinterp}
tutorial/syntax.tex+3−1
@@ -33,7 +33,9 @@ hand side describes its expansion. The syntax rule itself consists of:
3333\item \textbf{Keywords} --- here, \texttt{if}, \texttt{then} and \texttt{else}, which must
3434be valid identifiers
3535\item \textbf{Non-terminals} --- included in square brackets, \texttt{[test]}, \texttt{[t]}
36−and \texttt{[e]} here, which stand for arbitrary expressions
36+and \texttt{[e]} here, which stand for arbitrary expressions. To avoid parsing ambiguities,
37+these expressions cannot use syntax extensions at the top level (though they can be used
38+in parentheses).
3739\item \textbf{Symbols} --- included in quotations marks, e.g. \texttt{":="}
3840\end{itemize}
3941
tutorial/typesfuns.tex+1−1
@@ -66,7 +66,7 @@ Boolean expressions can be tested with the \texttt{if...then...else} construct:
6666
6767\begin{SaveVerbatim}{ifthenelse}
6868
69−*prims> if (x==6*6+6) then "The answer!" else "Not the answer"
69+*prims> if x == 6 * 6 + 6 then "The answer!" else "Not the answer"
7070"The answer!" : String
7171
7272\end{SaveVerbatim}