[<<][meta][>>][..]

Mon Aug 15 22:36:50 CEST 2011

## Join

So.. a Monad can be built from fmap and join. Since fmap is
conceptually simple to understand, what is join in the case of the SSM
monad?
M (M a) =
M ((s, s -> (a, s))) =
(s', s' -> ((s, s -> (a, s)), s'))
Let's try to implement that directly.
First in a form without initial state passing:
(s' -> ((s -> (a, s)), s'))
It looks like this is really just a straightforward translation to
"parallelize" the states:
((s',s), (s',s) -> (a, (s',s)))
I was able to write down join and map without too much trouble for
doing the 2 functions (init state pass + state chaining)
simulataneously.
type Sig s a = (s, s -> (a, s))
_join :: (Sig s1 (Sig s2 a)) -> Sig (s1,s2) a
_join (i1, u1) = ((i1, i2), u12) where
((i2, _), _) = u1 i1
u12 (s1, s2) = (a, (s1', s2')) where
((_, u2), s1') = u1 s1
(a, s2') = u2 s2
_fmap :: (a -> b) -> Sig s a -> Sig s b
_fmap f (s0, u) = (s0, u') where
u' s = (f a, s') where
(a, s') = u s

[Reply][About]

[<<][meta][>>][..]