Stable pointers might do what you want:<br><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-StablePtr.html">http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-StablePtr.html</a><br><br>Though an IORef would probably work just as well, depending on how you needed to use it..<br>
<br>- Job<br><br><div class="gmail_quote">On Fri, Oct 16, 2009 at 2:59 PM, Alan Carter <span dir="ltr">&lt;<a href="mailto:alangcarter@gmail.com">alangcarter@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<div><br></div><div>I&#39;ve been looking at the patches given by Tom at Beware the Jabberwolk, for building Linux kernel modules in Haskell. Once I&#39;d got Tom&#39;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&#39;ve now got a little function which can see all the characters which are catted to the device file. That&#39;s when I got stuck.</div>

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

<div><br></div><div>I&#39;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&#39;s ugly - having to use C for something Haskell can&#39;t do.</div>

<div><br></div><div>I&#39;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 :-(</div>

<div><br></div><div>So my questions are:</div><div><br></div><div>1) Am I right in thinking that I have a genuine need for global, persistent state?</div><div>2) Halfs works. Am I right in thinking it has (somehow) solved this problem?</div>

<div>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?</div><div><br></div>
<div>
Thanks in advance,</div><div><br></div><div>Alan</div><div><br>-- <br>... the PA system was moaning unctuously, like a lady hippopotamus reading A. E. Housman ...&quot;<br>  -- James Blish, &quot;They Shall Have Stars&quot;<br>


</div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>