[<<][compsci][>>][..]
Sat Feb 18 11:23:55 EST 2012

Functor in terms of Arrow

Dear HC,

Does AFunctor below have a standard name?  It's a generalization of
the Functor class in terms of Arrow instead of (->):

      fmap  :: Functor f           => (i -> o) -> f i  ->  f o
      afmap :: Arrow a, AFunctor f => a i o    -> a (f i) (f o)

It pops up in less general form (AFunctor = []) in iterated functions
(difference equations / state space models), where the arrow is the
update function parameterized by state type:

  data Iter s i o = Iter ((s,i) -> (s,o))
  instance Arrow (Iter s)

More concretely:

> afmap :: ((s,i) -> (s, o)) -> (s,[i]) -> (s,[o])
> afmap f (s,[]) = (s,[])
> afmap f (s0, i:is) = (sn, o:os) where
>  (s1, o)   = f (s0,i)
>  (sn, os)  = afmap f (s1, is)

> f (s,i) = (s', s') where s' = s + i
> is = [1,1,1,1,1]
> os = afmap f (0,is)  -- (5,[1,2,3,4,5])


Cheers,
Tom



[Reply][About]
[<<][compsci][>>][..]