Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created February 15, 2017 21:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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