Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active February 16, 2017 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/31d17efed3bd7cb356ead4e409a63a35 to your computer and use it in GitHub Desktop.
Save deque-blog/31d17efed3bd7cb356ead4e409a63a35 to your computer and use it in GitHub Desktop.
prnInfix :: Expr -> String
prnInfix = cata infixAlg where
infixAlg (Op Add xs) = concat (intersperse " + " xs)
infixAlg (Op Mul xs) = concat (intersperse " * " (map parens xs))
infixAlg (Cst n) = show n
infixAlg (Var v) = v
parens x = "(" ++ x ++ ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment