Re: framework for composing monads?

(Moving to haskell cafe...) On 18-Feb-2001 Manuel M. T. Chakravarty wrote:
It is even acceptable for me to manage the state in C - independent of the API design - but then some time there will be the question: Why do I always say that that Haskell is the better programming language, when I'm really doing all the tricky stuff in C?...
Sure - therefore, I proposed to use `IORef's rather than C routines.
Thanks for the hint! I took a look at them and now have some questions: a) It is clear that I need some C-link to access the cli/odbc lib. Up to now I planned to use Haskell Direct for this. Except of this, I want to stick to Haskell 98 and seek for maximal portability. Practically, this raises the question of wether nhc and hbc support hslibs or else I can provide a substitute for IORef's for these compilers. Can someone give me hint? b) What I finally need is "hidden state". My first attempt to get one using IORefs is:
import IOExts
state :: IORef Int state = unsafePerformIO $ newIORef 0
main = seq state $ do writeIORef state 1 currstate <- readIORef state putStr (show currstate)
Is this the right way? Cheers, Elke --- "If you have nothing to say, don't do it here..." Elke Kasimir Skalitzer Str. 79 10997 Berlin (Germany) fon: +49 (030) 612 852 16 mail: elke.kasimir@catmint.de> see: http://www.catmint.de/elke for pgp public key see: http://www.catmint.de/elke/pgp_signature.html

Elke Kasimir
(Moving to haskell cafe...)
On 18-Feb-2001 Manuel M. T. Chakravarty wrote:
It is even acceptable for me to manage the state in C - independent of the API design - but then some time there will be the question: Why do I always say that that Haskell is the better programming language, when I'm really doing all the tricky stuff in C?...
Sure - therefore, I proposed to use `IORef's rather than C routines.
Thanks for the hint!
I took a look at them and now have some questions:
a) It is clear that I need some C-link to access the cli/odbc lib. Up to now I planned to use Haskell Direct for this. Except of this, I want to stick to Haskell 98 and seek for maximal portability.
I am all for portable code, too.
Practically, this raises the question of wether nhc and hbc support hslibs or else I can provide a substitute for IORef's for these compilers.
nhc does supports `IORef's (they come in the module IOExtras). I am not sure whether H/Direct works with nhc, though. Sigbjorn should be able to answer this.
b) What I finally need is "hidden state". My first attempt to get one using IORefs is:
import IOExts
state :: IORef Int state = unsafePerformIO $ newIORef 0
main = seq state $ do writeIORef state 1 currstate <- readIORef state putStr (show currstate)
Is this the right way?
Yes, except that you want to have {-# NOINLINE state #-} too. Wouldn't be nice if ghc were to choose to inline `state', would it? ;-) Cheers, Manuel

Elke Kasimir writes:
Practically, this raises the question of wether nhc and hbc support hslibs or else I can provide a substitute for IORef's for these compilers.
As Manuel reported, nhc98 has IORefs identical to ghc and Hugs, except in module IOExtras. For hbc, you have an equivalent interface in: module IOMutVar where data MutableVar a newVar :: a -> IO (MutableVar a) readVar :: MutableVar a -> IO a writeVar :: MutableVar a -> a -> IO a sameVar :: MutableVar a -> MutableVar a -> Bool Regards, Malcolm
participants (3)
-
Elke Kasimir
-
Malcolm Wallace
-
Manuel M. T. Chakravarty