[Haskell-cafe] Execution Contexts

Keean Schupke k.schupke at imperial.ac.uk
Sat Nov 27 07:11:32 EST 2004

Jules Bean wrote:

> A problem is the ability to pass callbacks to external libraries...

Why not just put all the state in a record, then there's only one thing to
pass around... you can use the state monad to hide this (or the state monad
transformer if you need to layer over IO) then use partial function 
to pass the necessary state to the callback on creation?

Also another take on the TWI question... Doesn't this equate to the same 
as first class modules... then a module can be defined within the scope 
of a

printablePoint x_init = do
    x <- newIORef x_init

    return $ module PrintablePoint where
       getX = readIORef x

And the above can be seen as a model of an object... So using the HList 
you can write this:

class_printable_point x_init self = do
    x <- newIORef x_init
    returnIO $
        mutableX .=. x
        .*. getX .=. readIORef x
        .*. moveD .=. (\d -> modifyIORef x ((+) d))
        .*. ooprint .=. ((self # getX ) >>= print)
        .*. emptyRecord

Of course true top-level TWIs behave like static objects... But with dynamic
objects you can guarantee that each object is only initialised once, but
cannot guarantee that only one object of a given type exists (and I think
encapsulation is a more important property than uniqueness).


More information about the Haskell-Cafe mailing list