Trace and loop examples?
ross at soi.city.ac.uk
Tue Dec 16 14:11:15 EST 2003
On Tue, Dec 16, 2003 at 01:31:19PM +0100, Vincenzo aka Nick Name wrote:
> Hi all, I am trying to lear more about arrows in haskell, so I am
> reading the paper at:
> However, I can't understand how to produce a working and meaningful
> example of the trace function, or the loop arrow (I am using the
> "automata" example).
> The trace function is defined like:
> trace f b = let (c,d) = f (b,d) in c
> Can someone show an example function f to pass to trace and what the
> purpose is?
trace is one of many variants of fix; it's only interesting because
this variant generalizes to arrows. You wouldn't normally use fix or
its variants: you just use recursion. But a simple example is
trace (\(b,d) -> (d,b:d))
which is another way of writing repeat. However in the arrow world,
general recursion isn't available. The closest to it is loop (a
generalization of trace) but not all arrows provide that. (This extends
the situation for monads, which don't have recursion in general, but
many of them have mfix.)
More information about the Haskell-Cafe