No title

CritJongUn 2018-02-12 13:20:21.332855 UTC

1type Gen a = Seed -> (a, Seed)
2
3generalA :: (a -> b) -> Gen a -> Gen b
4generalA f g = applyOnVal f . g
5
6generalB :: (a -> b -> c) -> Gen a -> Gen b -> Gen c
7generalB x g1 g2 s = (x v1 v2, s2)
8 where
9 (v1, s1) = g1 s
10 (v2, s2) = g2 s1
11
12genTwo :: Gen a -> (a -> Gen b) -> Gen b
13genTwo gen f = (\(x, y) -> f x y) . gen
14
15applyOnSeed :: Gen b -> (a, Seed) -> (a, (b, Seed))
16applyOnSeed f (x, y) = (x, f y)
17
18applyOnVal :: (a -> b) -> (a, Seed) -> (b, Seed)
19applyOnVal f (x, y) = (f x, y)