
On Thu, 2010-04-01 at 09:32 -0500, aditya siram wrote:
Hi all, Could someone help me understand how the (->) instance for ArrowApply works? It looks like this:
instance ArrowLoop (->) where loop f b = let (c,d) = f (b,d) in c
This models recursion for arrows and I need help understanding how it does that. I have a strong feeling it has to do with the magic value 'd'. I've read the Patterson tutorial but I still don't grok it.
Thanks! -deech
f may be not strict in d (i.e. it may not require evaluate d to calculate result). For example if you want to create graph with cycle you can write: date Node a = Node a [Node] myGraph x = let n = Node x [n] in n Which is roughly equivalent to imperative: Node n = new Node(); n.addEdgeTo(n); return n; It is valid as constructors are not (usually) strict in arguments. Similarly you can write it as: myGraph = loop ((id &&& (:[])) <<< uncurry Node) or: myGraph = proc (x) -> do rec n <- uncurry Node -< (n, [n]) returnA -< n Usually I find let in more useful then (m)fix/loop but if code generalise for other monads/arrows this instance is needed. Regards