[Haskell-cafe] Design and state...
Stefan O'Rear
stefanor at cox.net
Wed Mar 21 10:19:20 EDT 2007
On Wed, Mar 21, 2007 at 09:28:15AM +0000, Magnus Therning wrote:
> Recently I've been hacking together a small Haskell module on top of
> ptrace(2). It's comming along nicely, but it's very low level. The
> signals arrive in a list:
>
> wait :: Int -> IO [Signal]
Aside: Why lazy? It seems like
wait :: Int -> IO Signal
would be better, and almost as easy to use:
sequence_ . repeat $ wait >>= processSignal
> and processing of the signals can be done using e.g. mapM_:
>
> wait childPid >>= mapM_ processSignal
>
[snip]
> (Or would it be better using IORefs and "OO" in the way described in "IO
> Inside"[1]?)
>
> What I am struggling with is how to allow the user of the module to have
> state as well. I can see how "OO"[1] can be used to solve it, but is
> there a more elegant, maybe more idiomatic (Haskellic??), way?
In some sense a PID is *already* a handle to external mutable state,
so the original motivation for IORefs applies.
data Child = Child { pid :: CInt, debug_state :: IORef StateBlock }
wait :: Child -> IO ()
...
HTH,
Stefan
More information about the Haskell-Cafe
mailing list