Первая версия Main, но пока с do-нотацией
This commit is contained in:
3
coursework/part1/.gitignore
vendored
3
coursework/part1/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.stack-work/
|
.stack-work/
|
||||||
*~
|
*~
|
||||||
!task_part1.txt
|
!task_part1.txt
|
||||||
|
!expressions.txt
|
||||||
@@ -3,4 +3,10 @@ module Main (main) where
|
|||||||
import Lib
|
import Lib
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn "temp"
|
main = do
|
||||||
|
putStrLn "Введите имя файла:"
|
||||||
|
fileName <- getLine
|
||||||
|
content <- readFile fileName
|
||||||
|
let expressions = lines content
|
||||||
|
putStrLn $ concatMap processExpression expressions
|
||||||
|
|
||||||
6
coursework/part1/expressions.txt
Normal file
6
coursework/part1/expressions.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
100 * 100
|
||||||
|
40 + 30
|
||||||
|
50 / 2
|
||||||
|
5 / 2
|
||||||
|
62 - 32
|
||||||
|
78 - 500
|
||||||
@@ -96,7 +96,7 @@ processExpression s = case runParser expression s of
|
|||||||
show a ++ " " ++
|
show a ++ " " ++
|
||||||
operationToString op ++ " " ++
|
operationToString op ++ " " ++
|
||||||
show b ++ " = " ++
|
show b ++ " = " ++
|
||||||
show (calculateExpression (a, op, b))
|
show (calculateExpression (a, op, b)) ++ "\n"
|
||||||
_ -> err
|
_ -> err
|
||||||
where
|
where
|
||||||
err = error $ "Unable to parse the following expression: \"" ++ s ++ "\""
|
err = error $ "Unable to parse the following expression: \"" ++ s ++ "\""
|
||||||
Reference in New Issue
Block a user