Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Environment
- import System.Exit
- import Data.List
- myElem :: Eq a => a -> [a] -> Bool
- myElem a [] = False
- myElem a (b:bs)
- | a == b = True
- | otherwise = myElem a bs
- checkIfInt :: [Char] -> Bool
- checkIfInt [] = False
- checkIfInt [a] = case myElem a ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] of
- True -> True
- False -> False
- checkIfInt (a:as) = case myElem a ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] of
- True -> checkIfInt as
- False -> False
- checkIfIntWithNegative :: [Char] -> Bool
- checkIfIntWithNegative [] = False
- checkIfIntWithNegative [a] = case myElem a ['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] of
- True -> True
- False -> False
- checkIfIntWithNegative (a:as) = case myElem a ['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] of
- True -> checkIfIntWithNegative as
- False -> False
- printElements :: [String] -> IO()
- printElements [] = return ()
- printElements (x:xs) = do putStrLn x
- printElements xs
- getNextArgs :: [String] -> String
- getNextArgs [] = "Empty"
- getNextArgs (x:xs) = x
- parseArgs :: [String] -> String -> String
- parseArgs [] b = "Empty"
- parseArgs (x:xs) b = case x == b of
- True -> getNextArgs xs
- False -> do
- parseArgs xs b
- checkRule :: [String] -> IO String
- checkRule arguments = do
- let rule = parseArgs arguments "--rule"
- let is_arg_int = checkIfInt rule
- if (is_arg_int == False)
- then do
- putStrLn ("No rule set")
- exitWith (ExitFailure 84)
- else
- return rule
- checkStart :: [String] -> IO String
- checkStart arguments = do
- let start = parseArgs arguments "--start"
- if start == "Empty"
- then return ("0")
- else do
- let is_arg_int = checkIfInt start
- if (is_arg_int == False)
- then do
- putStrLn ("Start is not an integer")
- exitWith (ExitFailure 84)
- else
- return start
- checkLine :: [String] -> IO String
- checkLine arguments = do
- let lines = parseArgs arguments "--lines"
- if lines == "Empty"
- then return ("0")
- else do
- let is_arg_int = checkIfInt lines
- if (is_arg_int == False)
- then do
- putStrLn ("Lines is not an integer")
- exitWith (ExitFailure 84)
- else
- return lines
- checkWindow :: [String] -> IO String
- checkWindow arguments = do
- let window = parseArgs arguments "--window"
- if window == "Empty"
- then return ("80")
- else do
- let is_arg_int = checkIfInt window
- if (is_arg_int == False)
- then do
- putStrLn ("Window is not an integer")
- exitWith (ExitFailure 84)
- else
- return window
- checkMove :: [String] -> IO String
- checkMove arguments = do
- let move = parseArgs arguments "--move"
- if move == "Empty"
- then return ("80")
- else do
- let is_arg_int = checkIfInt move
- if (is_arg_int == False)
- then do
- putStrLn ("Move is not an integer")
- exitWith (ExitFailure 84)
- else
- return move
- printSpaces :: Int -> IO()
- printSpaces 0 = putStr(" ")
- printSpaces x = do
- putStr(" ")
- printSpaces (x-1)
- main = do
- arguments <- getArgs
- rules <- checkRule arguments
- start <- checkStart arguments
- lines <- checkLine arguments
- window <- checkWindow arguments
- move <- checkMove arguments
- printSpaces 80
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement