Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- op2str :: Op -> String
- op2str Plus = " + "
- op2str Minus = " - "
- op2str Mul = " * "
- op2str Div = " / "
- op2str Pow = " ^ "
- prettyShow :: (Show a, Num a) => SymbolicManip a -> String
- prettyShow = fst . prettyShow'
- prettyShow' :: (Show a, Num a) => SymbolicManip a -> (String, Maybe Op)
- prettyShow' (Number x) = (show x, Nothing)
- prettyShow' (Symbol x) = (x, Nothing)
- prettyShow' (UnaryArith op2str a) = (op2str ++ "(" ++ show a ++ ")", Nothing)
- prettyShow' (BinaryArith op a b) =
- let (ra, mopa) = prettyShow' a
- (rb, mopb) = prettyShow' b
- opa = maybe op id mopa
- opb = maybe op id mopb
- pop = op2str op
- in if opa == op && opb == op then (ra ++ pop ++ rb, Just op)
- else if opa == op && opb /= op then (ra ++ pop ++ "(" ++ rb ++ ")", Just op)
- else if opa /= op && opb == op then ("(" ++ ra ++ ")" ++ pop ++ rb, Just op)
- else ("(" ++ ra ++ ")" ++ pop ++ "(" ++ rb ++ ")", Just op)
Add Comment
Please, Sign In to add comment