Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
calcRPN :: String -> [Double]
|
||||
calcRPN = foldl interprete [] . words
|
||||
|
||||
interprete s x
|
||||
| x `elem` ["+","-","*","/","^"] = operate x s
|
||||
| otherwise = read x:s
|
||||
where
|
||||
operate op (x:y:s) = case op of
|
||||
"+" -> x + y:s
|
||||
"-" -> y - x:s
|
||||
"*" -> x * y:s
|
||||
"/" -> y / x:s
|
||||
"^" -> y ** x:s
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
calcRPNLog :: String -> ([Double],[(String, [Double])])
|
||||
calcRPNLog input = mkLog $ zip commands $ tail result
|
||||
where result = scanl interprete [] commands
|
||||
commands = words input
|
||||
mkLog [] = ([], [])
|
||||
mkLog res = (snd $ last res, res)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import Control.Monad (foldM)
|
||||
|
||||
calcRPNIO :: String -> IO [Double]
|
||||
calcRPNIO = foldM (verbose interprete) [] . words
|
||||
|
||||
verbose f s x = write (x ++ "\t" ++ show res ++ "\n") >> return res
|
||||
where res = f s x
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class Monad m => Logger m where
|
||||
write :: String -> m ()
|
||||
|
||||
instance Logger IO where write = putStr
|
||||
instance a ~ String => Logger (Writer a) where write = tell
|
||||
|
||||
verbose2 f x y = write (show x ++ " " ++
|
||||
show y ++ " ==> " ++
|
||||
show res ++ "\n") >> return res
|
||||
where res = f x y
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
calcRPNM :: Logger m => String -> m [Double]
|
||||
calcRPNM = foldM (verbose interprete) [] . words
|
||||
Loading…
Add table
Add a link
Reference in a new issue