Skip to content

Instantly share code, notes, and snippets.

@eloidrai
Created November 15, 2020 13:00
Show Gist options
  • Save eloidrai/186c95af7c569054d04fdb7ff26286b9 to your computer and use it in GitHub Desktop.
Save eloidrai/186c95af7c569054d04fdb7ff26286b9 to your computer and use it in GitHub Desktop.
evalRPN exp = foldl calcul [] (words exp)
where
calcul (a:b:stack) "+" = (a+b):stack
calcul (a:b:stack) "*" = (a*b):stack
calcul (a:b:stack) "-" = (a-b):stack
calcul (a:b:stack) "/" = (a/b):stack
calcul (a:b:stack) "^" = (a**b):stack
calcul stack n = read n:stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment