fork download
  1. import Control.Monad.State
  2.  
  3. data Person = Person {
  4. id :: Int,
  5. name :: String
  6. } deriving Show
  7.  
  8. type MyState = Int
  9. startState = 0
  10.  
  11. tick :: State MyState Int
  12. tick = do
  13. n <- get
  14. put (n+1)
  15.  
  16. names = ["Adam","Barney","Charlie"]
  17.  
  18. (persons, lastId) = (`runState` startState) $ do
  19. forM names $ \thisName -> do
  20. newId <- tick
  21. return $ Person newId thisName
  22.  
  23. main = print persons
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:1:7:
    Could not find module `Control.Monad.State':
      Use -v to see a list of the files searched for.
stdout
Standard output is empty