[Haskell] threading mutable state through callbacks
Jules Bean
jules at jellybean.co.uk
Wed Oct 13 08:46:49 EDT 2004
On 13 Oct 2004, at 13:14, MR K P SCHUPKE wrote:
>> its almost commutative
>
> Does that have something to do with splitting the supply?
That is an approach to getting unique values, I think.
>> newIORef
>
> why not use 'newSTRef' and use the ST monad...
>
In the context of my original question, the answer is that the control
flow of the program passes through external libraries ('C' code, if you
like to think of it that way), and the callbacks in question have
signature IO(), so they are constrained to store all their state in the
IO monad.
Were it not for this problem, the ST monad would indeed seem more
elegant. And some explicit state monad with a nicely designed set of
state for your application is probably more elegant still... but
unfortunately that isn't possibly. Unless its possible to arrange
haskell FFI bindings to have types in MonadIO rather than IO... (a
question which I asked earlier but no one has answered).
Juels
More information about the Haskell
mailing list