Quantcast

recursive programming in applicative functors?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

recursive programming in applicative functors?

Conal Elliott
Is there a fixpoint operator for applicative functors, like mfix for MonadFix and loop for ArrowLoop?

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: recursive programming in applicative functors?

Ashley Yakeley
Conal Elliott wrote:
> Is there a fixpoint operator for applicative functors, like mfix for
> MonadFix and loop for ArrowLoop?

One of these?

  (fmap fix) :: m (a -> a) -> m a
  fix :: (m a -> m a) -> m a

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: recursive programming in applicative functors?

Ross Paterson
In reply to this post by Conal Elliott
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.

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Loading...