Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 20, 2015 07:04
Show Gist options
  • Select an option

  • Save shigemk2/6b933009bb52af37f9c6 to your computer and use it in GitHub Desktop.

Select an option

Save shigemk2/6b933009bb52af37f9c6 to your computer and use it in GitHub Desktop.
import Data.List.Split
rpn str = rpnPrime (splitOn " " str) []
rpnPrime ("+":t) (y:x:zs) = rpnPrime t $ x + y:zs
rpnPrime (n:t) zs = rpnPrime t $ read n:zs
rpnPrime _ (x:xs) = x
main = do
print $ rpn "1"
print $ rpn "1 2 +"
print $ rpn "1 2 3 + +"
print $ rpn "1 2 + 3 +"
print $ rpn "1 2 + 3 4 + +"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment