Answer the question
In order to leave comments, you need to log in
How to get rid of parentheses in Haskell?
Here is my Haskell code:
infixl 6 :$:
data ExE = ExData Integer | ExE :$: ExE deriving (Show, Eq)
simplify :: ExE -> ExE
simplify ((a1 :$: a2) :$: a3) = simplify a1 :$: simplify a2 :$: simplify a3
simplify (a1 :$: (a2 :$: a3)) = simplify a1 :$: simplify a2 :$: simplify a3
simplify (a1 :$: a2) = simplify a1 :$: simplify a2
simplify a = a
*ExTesting> simplify $ (ExData 1 :$: ExData 2) :$: ExData 3
(ExData 1 :$: ExData 2) :$: ExData 3
*ExTesting> simplify $ ExData 1 :$: (ExData 2 :$: ExData 3)
(ExData 1 :$: ExData 2) :$: ExData 3
*ExTesting> simplify $ (ExData 1 :$: ExData 2) :$: ExData 3
ExData 1 :$: ExData 2 :$: ExData 3
*ExTesting> simplify $ ExData 1 :$: (ExData 2 :$: ExData 3)
ExData 1 :$: ExData 2 :$: ExData 3
Answer the question
In order to leave comments, you need to log in
You can manually define show for ExE.
instance Show ExE where
show exe = case exe of
ExData i -> "ExData " ++ show i
e1 :$: e2 -> show e1 ++ " :$: " ++ show e2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question