[Haskell-cafe] Re: [Haskell] Arrows GUI Library Based on GTK+

ross at soi.city.ac.uk ross at soi.city.ac.uk
Tue Mar 22 18:15:54 EST 2005


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.


More information about the Haskell-Cafe mailing list