language: Haskell (ghc-7.4.1)
date: 217 days 13 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Control.Monad.State
 
data Person = Person {
  id   :: Int,
  name :: String
} deriving Show
 
type MyState = Int
startState = 0
 
tick :: State MyState Int
tick = do
  n <- get
  put (n+1)
  return n
 
names = ["Adam","Barney","Charlie"]
 
(persons, lastId) = (`runState` startState) $ do
   forM names $ \thisName -> do
      newId <- tick
      return $ Person newId thisName
 
main = print persons
prog.hs:1:7:
    Could not find module `Control.Monad.State':
      Use -v to see a list of the files searched for.