Created
February 15, 2017 21:21
-
-
Save deque-blog/3852067cf77a2ea2c9f17adeb11b4f4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prnInfix :: Expr -> String | |
prnInfix = para infixAlg where | |
infixAlg (Op Add xs) = concat (intersperse " + " (map fst xs)) | |
infixAlg (Op Mul xs) = concat (intersperse " * " (map parensPlus xs)) | |
infixAlg (Cst n) = show n | |
infixAlg (Var v) = v | |
parensPlus (s, Fix (Op Add _)) = "(" ++ s ++ ")" | |
parensPlus (s, _) = s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment