diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-07-23 22:11:17 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-07-23 22:13:43 +0100 |
commit | 318edd7c95b841024c2f7cfc7478aa9c601e12e5 (patch) | |
tree | 323f7b94ea880c9fd2e9cff5a82f4a5c790b8a2d /Main.hs | |
parent | 09940ff8297ccbe4e061a25b1cfd7dfa96f6950b (diff) | |
download | numberdisplay-318edd7c95b841024c2f7cfc7478aa9c601e12e5.tar.gz numberdisplay-318edd7c95b841024c2f7cfc7478aa9c601e12e5.tar.bz2 numberdisplay-318edd7c95b841024c2f7cfc7478aa9c601e12e5.zip |
(General)~moved cli files into seperate folder to make space for website
Diffstat (limited to 'Main.hs')
-rw-r--r-- | Main.hs | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/Main.hs b/Main.hs deleted file mode 100644 index e8b2927..0000000 --- a/Main.hs +++ /dev/null @@ -1,69 +0,0 @@ -import Math -import System.Environment -import Data.List -import Text.Printf - -errorMessage :: String -> String - -errorMessage "" = "nd v1\nUsage: nd [-help, -int, -prime, -factor, -hcf]\n" -errorMessage reason = "nd v1\nFAILURE: " - ++ reason - ++ "\nUsage: nd [-int, -prime, -factor, -hcf]\n" - -flagHandlerF :: [String] -> Int -> String -> ([String] -> String) -> String - -flagHandlerF args (-1) error fmessage = - if (length args) == 0 - then error - else - (fmessage args) - -flagHandlerF args nargs error fmessage = - if (length args) /= nargs - then error - else - (fmessage args) - -flagHandler :: String -> [String] -> String - -flagHandler "-prime" args = - flagHandlerF args (-1) - (errorMessage "-prime requires at least one integer argument") - (\args -> - foldl (++) "" [show y ++ ": isPrime=" ++ (show $ isPrime y) - ++ "\n" | x <- args, let y = (read x) :: Int]) - -flagHandler "-factor" args = - flagHandlerF args (-1) - (errorMessage "-factor requires at least one integer argument") - (\args -> - foldl (++) "" [show y ++ ": factors=" ++ show (factors $ y) - | x <- args, let y = (read x) :: Int]) - -flagHandler "-int" args = - flagHandlerF args (-1) - (errorMessage "-int requires at least one integer argument") - (\args -> - foldl (++) "" [show y ++ ": (isPrime=" ++ (show $ isPrime y) - ++ ", factors=" ++ (show $ factors y) - ++ ")\n" | x <- args, let y = (read x) :: Int]) - -flagHandler "-hcf" args = - flagHandlerF args (2) - (errorMessage "-hcf requires two integer arguments") - (\args -> - let n = (read $ head args) :: Int - m = (read $ head $ tail args) :: Int - hcf = head $ reverse $ intersect (factors n) (factors m) in - "hcf(" ++ show n ++ ", " ++ show m ++ "): hcf=" ++ show hcf) - -flagHandler _ _ = - errorMessage "Flag not recognised" - - -main = do - args <- getArgs - putStr $ - case args of - [] -> errorMessage "" - (x: xs) -> if x == "-help" then errorMessage "" else flagHandler x xs |