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

Mon Aug 15 12:49:11 CEST 2011

## Applicative?

So.. I have the following: series / parallel composition and pure
functions.
serSSM :: ((s1, b) -> (s1, c)) ->
((s2, a) -> (s2, b)) ->
((s1,s2), a) -> ((s1,s2), c)
serSSM f g = fg where
fg ((s1,s2), a) = ((s1',s2'), c) where
(s2', b) = g (s2, a)
(s1', c) = f (s1, b)
parSSM :: ((s1, a) -> (s1, c)) ->
((s2, b) -> (s2, d)) ->
((s1,s2), (a,b)) -> ((s1,s2), (c,d))
parSSM f g = fg where
fg ((s1,s2), (a,b)) = ((s1',s2'), (c,d)) where
(s1',c) = f (s1, a)
(s2',d) = g (s2, b)
pureSSM :: (a -> b) -> ((), a) -> ((), b)
pureSSM f (_,a) = ((), f a)
I wonder if parallel composition is really necessary since it seems to
be mostly useful for doing things like:
a -> b -> (a,b) -> (a+b)
I.e. replacing the tuple by an arithmetic reduction.
Maybe it's enough to just allow for input/output/state to contain
curried functions. Then Applicative can be used.
This doesn't work because my abstraction is Arrow-like (explicit
input/output, kind * -> * -> *) and Applicative is Functor-like (* ->
*). See also [1]. It seems Applicative needs a "generator" approach
instead of a "processor" approach.
I'm first trying for Functor:
instance Functor (SSM i) where
fmap f a = (SSM () $ pureSSM f) . a
This works!
*Main> fmap (1+) int
[2,2,2,2,2,2,2,2,2,2]
The case for mapping over inputs should be completely symmetric,
though I don't know how to "flip" the arguments of the type
constructor SSM. As mentioned here[2] it's possible to use a
Bifunctor instead.
So the trick seems to be to focus on the output. Let's try
Applicative. There it seems to go wrong. Paraphrased: x is a value
while pureSSM expects a function.
instance Applicative (SSM i) where
pure x = SSM () $ pureSSM x
So.. is it really necessary? It doesn't look like it. Ser/par +
Functor seem to be really enough.
[1] http://cdsmith.wordpress.com/2011/07/30/arrow-category-applicative-part-i/
[2] http://stackoverflow.com/questions/2335967/manipulating-the-order-of-arguments-to-type-constructors
[3] http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Functor.html

[Reply][About]

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