Skip to content

Instantly share code, notes, and snippets.

@Mine02C4
Created October 4, 2015 22:37
Show Gist options
  • Select an option

  • Save Mine02C4/007371ac519e14a27bb5 to your computer and use it in GitHub Desktop.

Select an option

Save Mine02C4/007371ac519e14a27bb5 to your computer and use it in GitHub Desktop.
情報論理学 10月5日 提出レポート
isBinaryOperator = flip elem ['*','+','>','=']
isUnaryOperator = flip elem ['-']
prefixToInfix str
| isBinaryOperator token =
let left = prefixToInfix $ tail str
right = prefixToInfix $ snd left
in ("(" ++ fst left ++ [token] ++ fst right ++ ")", snd right)
| isUnaryOperator token =
let sub = prefixToInfix $ tail str
in ("(" ++ [token] ++ fst sub ++ ")", snd sub)
| otherwise = ([token], tail str)
where token = head str
main = do
contents <- getContents
putStr $ unlines $ map (fst . prefixToInfix) $ lines contents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment