Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Stack(Stack,emptyStack,iSE) where
- data Stack a = Leer | Cons a deriving Show
- emptyStack = []
- iSE:: [a]-> Bool
- iSE [] = True
- iSE _ = False
- -- push :: a -> a -> [a]
- push s e= s ++ [e]
- top s = s !! (length s -1)
- pop :: [a] -> [a]
- pop = init
- s= push (push [2.0] 7.0) 3.0
- -- module Stack(Stack,emptyStack,iSE) where
- -- data Stack a = Leer | Cons a (Stack a)
- diev :: Int -> Int -> Int
- diev a b | a < b = 0
- | otherwise = (diev (a - b ) b) +1
- add :: [Float]->[Float]
- add s | length s > 2 = push (pop (pop s)) ((s !! ((length s) - 2)) + (s !! ((length s) -1)))
- | length s == 2 = push emptyStack ((s !! ((length s) - 2)) + (s !! ((length s) -1)))
- | otherwise = error"2249"
- sub :: [Float]->[Float]
- sub s | length s > 2 = push (pop (pop s)) ((s !! ((length s) - 2)) - (s !! ((length s) -1)))
- | length s == 2 = push emptyStack ((s !! ((length s) - 2)) - (s !! ((length s) -1)))
- | otherwise = error"2253"
- mul :: [Float]->[Float]
- mul s | length s > 2 = push (pop (pop s)) ((s !! ((length s) - 2)) * (s !! ((length s) -1)))
- | length s == 2 = push emptyStack ((s !! ((length s) - 2)) * (s !! ((length s) -1)))
- | otherwise = error"2249"
- pdiv :: [Float]->[Float]
- pdiv s | length s > 2 = push (pop (pop s)) ( (s !! ((length s) - 2)) / (s !! ((length s) -1)))
- | length s == 2 = push emptyStack ( (s !! ((length s) - 2)) / (s !! ((length s) -1)))
- | otherwise = error"2249"
- main :: IO()
- main = print(add (add s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement