packages feed

Stack 0.3.1 → 0.3.2

raw patch · 5 files changed

+90/−25 lines, 5 filesdep ~natsdep ~stmPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: nats, stm

API changes (from Hackage documentation)

+ Data.Stack.ST: data Stack s a
+ Data.Stack.ST: stackIsEmpty :: Stack s a -> ST s Bool
+ Data.Stack.ST: stackNew :: ST s (Stack s a)
+ Data.Stack.ST: stackPeek :: Stack s a -> ST s (Maybe a)
+ Data.Stack.ST: stackPop :: Stack s a -> ST s (Maybe a)
+ Data.Stack.ST: stackPush :: Stack s a -> a -> ST s ()
+ Data.Stack.ST: stackSize :: Stack s a -> ST s Natural

Files

Stack.cabal view
@@ -1,25 +1,34 @@-name:                Stack-version:             0.3.1-synopsis:            Stack data structure-description:         A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items takes place at one end called top of the stack.-                     .-                     <<https://upload.wikimedia.org/wikipedia/commons/b/b4/Lifo_stack.png>>-homepage:            https://en.wikipedia.org/wiki/Stack_(abstract_data_type)-license:             BSD3-license-file:        LICENSE-author:              Robert Walker-maintainer:          rwlock404@yahoo.com-copyright:           2016 Robert Walker-category:            Data Structures-build-type:          Simple-cabal-version:       >=1.10+name: Stack+version: 0.3.2+cabal-version: >=1.10+build-type: Simple+license: BSD3+license-file: LICENSE+copyright: 2016 Robert Walker+maintainer: rwlock404@yahoo.com+homepage: https://en.wikipedia.org/wiki/Stack_(abstract_data_type)+synopsis: Stack data structure+description:+    A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items takes place at one end called top of the stack.+    .+    <<https://upload.wikimedia.org/wikipedia/commons/b/b4/Lifo_stack.png>>+category: Data Structures+author: Robert Walker +source-repository head+    type: git+    location: https://github.com/githubuser/Stack+ library-  hs-source-dirs:      src-  exposed-modules:     Data.Stack, Control.Concurrent.STM.Stack, Control.Concurrent.Stack-  build-depends:       base >= 4.7 && < 5, nats, stm-  default-language:    Haskell2010+    exposed-modules:+        Data.Stack+        Data.Stack.ST+        Control.Concurrent.STM.Stack+        Control.Concurrent.Stack+    build-depends:+        base >=4.7 && <5,+        nats >=1.1.1 && <1.2,+        stm >=2.4.4.1 && <2.5+    default-language: Haskell2010+    hs-source-dirs: src -source-repository head-  type:     git-  location: https://github.com/githubuser/Stack
src/Control/Concurrent/STM/Stack.hs view
@@ -22,7 +22,7 @@ -- | Synchronized stack data type newtype Stack a = Stack (TVar (Pure.Stack a)) --- | Create new Stack+-- | Create new empty Stack stackNew :: STM (Stack a) stackNew = do     stackRef <- newTVar Pure.stackNew
src/Control/Concurrent/Stack.hs view
@@ -20,7 +20,7 @@ import qualified Control.Concurrent.STM.Stack as STM import Control.Concurrent.STM.Stack (Stack) --- | Create new Stack+-- | Create new empty Stack stackNew :: IO (Stack a) stackNew = atomically STM.stackNew 
src/Data/Stack.hs view
@@ -23,7 +23,7 @@ -- | Abstract Stack data type data Stack a = Stack !Natural [a] deriving (Read,Show) --- | /O(1)/. Create new Stack+-- | /O(1)/. Create new empty Stack stackNew :: Stack a stackNew = Stack 0 [] 
+ src/Data/Stack/ST.hs view
@@ -0,0 +1,56 @@+-- | Provides a stack container for use in the 'ST' monad+module Data.Stack.ST (+    Stack,+    stackNew,+    stackPush,+    stackPeek,+    stackPop,+    stackIsEmpty,+    stackSize,+  )+  where++import Data.STRef+import Control.Monad.ST+import qualified Data.Stack as Pure+import Numeric.Natural++-- | A mutable stack in state thread s, containing values of type a+newtype Stack s a = Stack (STRef s (Pure.Stack a))++-- | Create new empty Stack+stackNew :: ST s (Stack s a)+stackNew = do+    stackRef <- newSTRef Pure.stackNew+    return (Stack stackRef)++-- | Push item onto Stack+stackPush :: Stack s a -> a -> ST s ()+stackPush (Stack stackRef) item = modifySTRef' stackRef (\stack -> Pure.stackPush stack item)++-- | Pop most recently added item without removing from the Stack+stackPeek :: Stack s a -> ST s (Maybe a)+stackPeek (Stack stackRef) = do+    stack <- readSTRef stackRef+    return (Pure.stackPeek stack)++-- | Pop most recently added item from Stack+stackPop :: Stack s a -> ST s (Maybe a)+stackPop (Stack stackRef) = do+    stack <- readSTRef stackRef+    case Pure.stackPop stack of+      Just (stack1,item) -> do writeSTRef stackRef stack1+                               return (Just item)+      Nothing -> return Nothing++-- | Test if stack is empty+stackIsEmpty :: Stack s a -> ST s Bool+stackIsEmpty (Stack stackRef) = do+    stack <- readSTRef stackRef+    return (Pure.stackIsEmpty stack)++-- | Compute number of elements contained in the Stack+stackSize :: Stack s a -> ST s Natural+stackSize (Stack stackRef) = do+    stack <- readSTRef stackRef+    return (Pure.stackSize stack)