multistate 0.1.3.1 → 0.1.3.2
raw patch · 2 files changed
+29/−37 lines, 2 files
Files
- example/Example.hs +14/−21
- multistate.cabal +15/−16
example/Example.hs view
@@ -17,30 +17,23 @@ 1) a MultiState containing a Char and a [Char], 2) the polymorphic mGet, 3) how to initially put values into the MultiState using withMultiState,- 4) the type inference at work - note that we omitted all type signatures.+ 4) the type inference at work - note that there was no need to annotate+ combinedPrint -} ---examplePrint :: MultiStateT (Cons [Char] (Cons Char Null)) IO ()--- or more general:---examplePrint :: ( MonadMultiState [Char] m--- , MonadMultiState Char m--- , m~MultiStateT x IO)--- => m ()-simpleExamplePrint = do- c <- mGet- cs <- mGet- lift $ putStrLn (c:cs)--simpleExampleAction = do- simpleExamplePrint+simpleExample :: IO ()+simpleExample = evalMultiStateT+ $ withMultiState 'H'+ $ withMultiState "ello, World!"+ $ do+ -- the monad here is MultiStateT (Cons [Char] (Cons Char Null)) IO+ let combinedPrint = do+ c <- mGet+ cs <- mGet+ lift $ putStrLn (c:cs)+ combinedPrint mSet 'J'- simpleExamplePrint--simpleExample = do- evalMultiStateT- $ withMultiState 'H'- $ withMultiState "ello, World!"- $ simpleExampleAction+ combinedPrint -- output: -- "Hello, World!
multistate.cabal view
@@ -1,5 +1,5 @@ Name: multistate-Version: 0.1.3.1+Version: 0.1.3.2 Cabal-Version: >= 1.8 Build-Type: Simple license: BSD3@@ -29,22 +29,21 @@ . == Example .- > -- an IO action wrapped by a MultiState- > -- containing both a Char and a [Char].- > examplePrint :: MultiStateT (Cons [Char] (Cons Char Null)) IO ()- > examplePrint = do- > c <- mGet -- inferred to be :: m Char- > cs <- mGet -- inferred to be :: m [Char]- > lift $ putStrLn (c:cs)- .- This computation can be executed in the following way:- .- > main = evalMultiStateT- > $ withMultiState 'H'- > $ withMultiState "ello, World!"- > $ examplePrint+ > simpleExample :: IO ()+ > simpleExample = evalMultiStateT+ > $ withMultiState 'H'+ > $ withMultiState "ello, World!"+ > $ do+ > -- the monad here is MultiStateT (Cons [Char] (Cons Char Null)) IO+ > let combinedPrint = do -- no type signature necessary+ > c <- mGet -- type of mGet inferred to be m Char+ > cs <- mGet -- inferred to be m [Char]+ > lift $ putStrLn (c:cs)+ > combinedPrint+ > mSet 'J' -- similarly for the setter+ > combinedPrint .- the output is:+ The output is: . > Hello, World! > Jello, World!