On Tue, 22 Mar 2005 [EMAIL PROTECTED] wrote: > On Tue, Mar 22, 2005 at 09:52:04AM -0700, Kevin Atkinson wrote: > > I must admit that I am baffled by what this is doing. But I don't think > > it has the semantics I want. When I try substituting your > > code in I get "Exception: <<loop>>". > > I could have made it a bit simpler: > > instance ArrowLoop FG' where > loop (FG' f) = FG' $ \ c x -> do > (c', ~(x', _)) <- mfix $ \ ~(_, ~(_, y)) -> f c (x, y) > return (c', x') > > This executes f once only, with y bound to the third component of the > output of f. This isn't available until f finishes, so any attempt > to examine it while f is running will lead to <<loop>>, but f can pass > it around, and store it in data structures; it can even create cyclic > structures. (Under the hood, the IO instance of mfix starts with y bound > to an exception, and updates it when f finishes, a bit like what you're > trying to do with IORef's, except that existing references to y then > point at the updated thing.) Your definition runs f once with undefined > as the last argument to get a value for y to supply to a second run. > Presumably the things you're doing with Control need to change too, > and I don't understand all that, but I expect that the mfix version > could be made to work, and would do less work.
I think I understand it more, but I am not sure it will do what I want. For one thing f still needs to know when it can examine its input thus, still needing an initializing pass. Please have a look at the new code. I have reworked how loops are handled and no longer use Control. Also the state variable is now needed in separate functions. Thus I am not sure I can use the mfix trick to hide the state. _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
