recursive programming in applicative functors?
Ross Paterson
ross at soi.city.ac.uk
Fri Mar 16 20:07:57 EDT 2007
On Thu, Mar 15, 2007 at 09:34:21AM -0700, Conal Elliott wrote:
> Is there a fixpoint operator for applicative functors, like mfix for
> MonadFix and loop for ArrowLoop?
Hmm, there could be an afix :: (a -> f a) -> f a; I wonder what axioms
it would satisfy. These ones for mfix would carry over:
purity
afix (pure . h) = pure (fix h)
sliding
afix (fmap h . f) = fmap h (afix (f . h)), for strict h.
nesting
afix (\x -> afix (\y -> f x y)) = afix (\x -> f x x)
but there'd be no way to express tightening laws. Perhaps
afix (\(x, y) -> pair (f x) (g y)) = pair (afix f) (afix g)
where pair a b = (,) <$> a <*> b
Do you have any non-monadic examples in mind? I guess zip-lists are
one possibility.
More information about the Libraries
mailing list