[Haskell-cafe] Re: questions about Arrows
Ben
midfield at gmail.com
Wed Sep 1 14:49:18 EDT 2010
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.
>> 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)
In which case my question is, why is the primitive for Arrows based on
trace instead of fix?
Best regards, Ben
More information about the Haskell-Cafe
mailing list