Bladeren bron

Demonstrate use of forM_ in the example.

Lucas Stadler 13 jaren geleden
bovenliggende
commit
7794c78fad
1 gewijzigde bestanden met toevoegingen van 4 en 1 verwijderingen
  1. 4 1
      hs/ImperativeProgramming.hs

+ 4 - 1
hs/ImperativeProgramming.hs

7
7
8
import Data.Maybe (fromJust)
8
import Data.Maybe (fromJust)
9
import qualified Data.Map as M
9
import qualified Data.Map as M
10
import Control.Monad (liftM)
10
import Control.Monad (liftM, forM_)
11
import Control.Applicative ((<$>), (<*>))
11
import Control.Applicative ((<$>), (<*>))
12
12
13
example = do
13
example = do
14
    "x" .= 3
14
    "x" .= 3
15
    "x" .+= 4
15
    "x" .+= 4
16
    "y" .= (-1)
16
    "y" .= (-1)
17
    "z" .= 0
18
    forM_ [1..10] $ \n ->
19
        "z" .-= n
17
    "x" .+ "y"
20
    "x" .+ "y"
18
21
19
data Imperative a b = Imperative (M.Map String a -> (M.Map String a, b))
22
data Imperative a b = Imperative (M.Map String a -> (M.Map String a, b))