Maciej Piechotka uzytkownik2 at gmail.com
Wed Sep 1 15:28:20 EDT 2010

```On Wed, 2010-09-01 at 11:49 -0700, Ben wrote:
> Thanks for the prompt reply.  Some questions / comments below :
>
> On Wed, Sep 1, 2010 at 12:33 AM, Maciej Piechotka <uzytkownik2 at gmail.com> wrote:
>
> > rSum2 :: ArrowCircuit a => a Int Int
> > rSum2 = proc x -> do
> >    rec out <- delay 0 -< out + x
> >    returnA -< out + x
>
> Wow, that was simple.  I guess I never thought to do this because it
> evaluates (out + x) twice, but one can always write
>
> rSum3 :: ArrowCircuit a => a Int Int
> rSum3 = proc x -> do
>   rec let next = out + x
>       out <- delay 0 -< next
>   returnA -< next
>
> I have a follow-up question which I'll ask in a new thread.
>

Possibly it should be written as

rSum4 :: ArrowCircuit a => a Int Int
rSum4 = proc x -> do
rec let !next = out + x
out <- delay 0 -< next
returnA -< next

> >> 3) One can define fix in terms of trace and trace in terms of fix.
> >>
> >> trace f x = fst \$ fix (\(m, z) -> f (x, z))
> >> fix f = trace (\(x, y) -> (f y, f y)) undefined
> >>
> >> Does this mean we can translate arbitrary recursive functions into
> >> ArrowLoop equivalents?
> >>
> >
> > Yes. In fact fix is used on functional languages that do not support
> > recursion to have recursion (or so I heard)
>

Ups. Sorry - my dyslexia came to me and I read recursive instead of
ArrowLoop. My fault

IMHO it is not possible.

> In which case my question is, why is the primitive for Arrows based on
>

How would you define loop in terms of

fixA :: ArrowLoop a => a b b -> a c b
fixA f = loop (second f >>> arr (\(_, x) -> (x, x)))

The only way that comes to my mind is:

loopA :: (ArrowLoop a, ArrowApply a) => a (b, d) (c, d) -> a b c
loopA f = proc (x) -> do
arr fst <<< fixA (proc (m, z) -> do f -< (x, z)) -<< x

Which requires ArrowApply. So as long as arrow is ArrowLoop and
ArrowApply it is possible.

> Best regards, Ben

Regards

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part