State Transformer
Ashley Yakeley
ashley@semantic.org
Fri, 11 Jan 2002 23:31:55 -0800
At 2002-01-11 06:18, Jorge Adriano wrote:
>The whole problem is with passing the 'r' as a parameter, which is precisly
>what I'm trying to avoid.
You could always pass it implicitly (using -fglasgow-exts):
--
testfunc = do
r <- newSTRef ('x',0)
(do
foo
bar
with ?ref = r)
(c,n) <- readSTRef r
return n
foo :: (Num a,?ref :: STRef s (Char,a)) => ST s ()
foo = do
(c,n) <- readSTRef ?ref
writeSTRef ?ref ('a', n+1)
bar :: (Num a,?ref :: STRef s (t,a)) => ST s ()
bar = do
(c,n) <- readSTRef ?ref
writeSTRef ?ref (c,n+2)
tryTestFunc = runST testfunc
--
Curiously, GHC isn't smart enough to infer the types of foo and bar by
itself.
--
Ashley Yakeley, Seattle WA