Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List  
  2.  
  3. solveRPN :: String -> Float  
  4. solveRPN = head . foldl foldingFunction [] . words  
  5.     where   foldingFunction (x:y:ys) "*" = (x * y):ys  
  6.             foldingFunction (x:y:ys) "+" = (x + y):ys  
  7.             foldingFunction (x:y:ys) "-" = (y - x):ys  
  8.             foldingFunction (x:y:ys) "/" = (y / x):ys  
  9.             foldingFunction (x:y:ys) "^" = (y ** x):ys  
  10.             foldingFunction (x:xs) "ln" = log x:xs  
  11.             foldingFunction xs "sum" = [sum xs]  
  12.             foldingFunction xs numberString = read numberString:xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement