aboutsummaryrefslogtreecommitdiff
path: root/src/main.hs
blob: 4b365a2472887d46259bef9ab77cd8dc8fcb9a6f (plain)
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
import System.Environment
import Data.List

import Parser
import Equation

main :: IO ()
main = do
    args <- getArgs
    checkArgs args
    equ <- checkParsing (head args)
    let reduced = reduce equ
    putStrLn $ "Reduced From: " ++ show reduced
    putSolutions (left reduced)


checkArgs :: [String] -> IO ()
checkArgs args
    | length args == 0 = fail "Usage ./computor equation"
    | length args > 1  = fail "Too many arguments"
    | otherwise        = return ()

checkParsing :: String -> IO Equation
checkParsing input = case parse Parser.equationP input
                        of Nothing        -> fail "Couldnt parse equation"
                           Just (equ, "") -> return equ
                           Just (_, s)    -> fail "Couldnt parse equation yo"

putSolutions :: Polynomial -> IO ()
putSolutions p
    | degree p > 2 = fail "The polynomial degree is strictly greater then 2, can't solve."
    | otherwise    = putStr $ intercalate "\n" (map show (solve p))