<div dir="ltr">Roman, this is interesting. Is this arrow generalization in some library already? And does it have a name?<div><br></div><div>Best regards,</div><div>Petr Pudlak</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/1/27 Roman Cheplyaka <span dir="ltr"><<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* Petr P <<a href="mailto:petr.mvd@gmail.com">petr.mvd@gmail.com</a>> [2013-01-26 23:03:51+0100]<br>
<div class="im">> Dear Haskellers,<br>
><br>
> I read some stuff about attribute grammars recently [1] and how UUAGC [2]<br>
> can be used for code generation. I felt like this should be possible inside<br>
> Haskell too so I did some experiments and I realized that indeed<br>
> catamorphisms can be represented in such a way that they can be combined<br>
> together and all run in a single pass over a data structure. In fact, they<br>
> form an applicative functor.<br>
><br>
</div>> ...<br>
<div class="im">><br>
> My experiments together with the example are available at <a href="https://github" target="_blank">https://github</a><br>
> .com/ppetr/recursion-attributes<br>
<br>
</div>Very nice! This can be generalized to arbitrary arrows:<br>
<br>
{-# LANGUAGE ExistentialQuantification #-}<br>
<br>
import Prelude hiding (id)<br>
import Control.Arrow<br>
import Control.Applicative<br>
import Control.Category<br>
<br>
data F from to b c = forall d . F (from b d) (to d c)<br>
<br>
instance (Arrow from, Arrow to) => Functor (F from to b) where<br>
fmap f x = pure f <*> x<br>
<br>
instance (Arrow from, Arrow to) => Applicative (F from to b) where<br>
pure x = F (arr $ const x) id<br>
F from1 to1 <*> F from2 to2 =<br>
F (from1 &&& from2) (to1 *** to2 >>> arr (uncurry id))<br>
<br>
Now your construction is a special case where 'from' is the category of<br>
f-algebras and 'to' is the usual (->) category.<br>
<br>
I wonder what's a categorical interpretation of F itself.<br>
<span class="HOEnZb"><font color="#888888"><br>
Roman<br>
</font></span></blockquote></div><br></div>