[Haskell-cafe] Genuine Need For Persistent Global State?

Don Stewart dons at galois.com
Fri Oct 16 15:02:29 EDT 2009


alangcarter:
> 1) Am I right in thinking that I have a genuine need for global, persistent
> state?
> 2) Halfs works. Am I right in thinking it has (somehow) solved this problem?
> 3) Is there a simple way to maintain global persistent state that I can stash
> between calls into a function, and access without needing to pass the state in?
> If so, is there an example anywhere?

You don't necessarily need to have global mutable state, since you can
pass a reference to the state back and forth from C. That saves you
having to build a top level table on the Haskell side to store all the
state while you're in C.

However, you can stash state on the Haskell side via a top level IORef,
or you can make a foreign pointer of the Haskell state, and pass  it to
C and back. I'd probably do the former.

-- Don


More information about the Haskell-Cafe mailing list