Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created February 15, 2017 21:21
Show Gist options
  • Save deque-blog/3852067cf77a2ea2c9f17adeb11b4f4f to your computer and use it in GitHub Desktop.
Save deque-blog/3852067cf77a2ea2c9f17adeb11b4f4f to your computer and use it in GitHub Desktop.
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