File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed
chapter-23/try-random/app Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,6 @@ intToDie x
24
24
| x == 6 = DieSix
25
25
| otherwise = error $ " intToDie got non 1-6 integer: " ++ show x
26
26
27
- main :: IO ()
28
- main = undefined
29
-
30
27
rollDiceThreeTimes :: (Die , Die , Die )
31
28
rollDiceThreeTimes = do
32
29
let s = mkStdGen 0
@@ -102,3 +99,33 @@ instance Monad (Moi s) where
102
99
let (a, _) = f x
103
100
Moi (gb) = g a
104
101
in gb x
102
+
103
+ main = undefined
104
+
105
+ {- exercises-}
106
+ {- ex1-}
107
+ get :: Moi s s
108
+ get = Moi $ \ x -> (x, x)
109
+ {- usage is-}
110
+ {- (put "blah") "woot"-}
111
+
112
+ {- ex2-}
113
+ put :: s -> Moi s ()
114
+ put s = Moi $ \ _ -> (() , s)
115
+
116
+ {- usage is-}
117
+ {- (put "blah") "woot"-}
118
+
119
+ {- ex3-}
120
+ exec :: Moi s a -> s -> s
121
+ exec (Moi sa) = snd . sa
122
+
123
+ {- ex4-}
124
+ eval :: Moi s a -> s -> a
125
+ eval (Moi sa) = fst . sa
126
+
127
+ {- ex5-}
128
+ modify :: (s -> s ) -> Moi s ()
129
+ modify f = (Moi $ \ s -> (() , f s))
130
+
131
+ ex5 = runMoi (Main. modify (+ 1 ) >> Main. modify (+ 1 )) 0
You can’t perform that action at this time.
0 commit comments