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

Alan Carter alangcarter at gmail.com
Fri Oct 16 14:59:16 EDT 2009


Hi,
I've been looking at the patches given by Tom at Beware the Jabberwolk, for
building Linux kernel modules in Haskell. Once I'd got Tom's stuff building,
the next thing was to build a little driver which actually does something.
Step by step I was making progress, and I've now got a little function which
can see all the characters which are catted to the device file. That's when
I got stuck.

Trouble is, my function is (ultimately) being called from the C kernel
stuff. It isn't on the bottom of a call graph coming from a Haskell main. A
driver really needs to know where it's at. So I seem to need some kind of
global, persistent state, and Control.Monad.State seems to be out because I
can't pass a State around my call graph.

I've thought about trying to create some State when I initialize, pass some
kind of pointer back to the C shim which actually does the calling into
Haskell, and then passing it back into Haskell on the writes and reads, but
that seems dangerous because the Haskell garbage collector would
(understandably) get the wrong idea and delete it. Also it's ugly - having
to use C for something Haskell can't do.

I've been looking at the Halfs Haskell file system, which surely must have
solved its own version of this problem, but whatever it does in its FSState
seems very complicated and is beyond my comprehension :-(

So my questions are:

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?

Thanks in advance,

Alan

-- 
... the PA system was moaning unctuously, like a lady hippopotamus reading
A. E. Housman ..."
 -- James Blish, "They Shall Have Stars"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091016/d3951d27/attachment.html


More information about the Haskell-Cafe mailing list