No title

CritJongUn 2018-02-13 00:24:27.541246 UTC

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