26 Jan
2004
26 Jan
'04
1:41 a.m.
I wrote:
newRef :: a -> (exists s . Ref s a, ^st s :: State) readRef :: (?st s :: State) => Ref s a -> (a, ^st s :: State) writeRef :: (?st s :: State) => Ref s a -> a -> ((), ^st s :: State)
(It's not clear that readRef actually needs to return the state.)
It shouldn't, and neither should writeRef need to *take* the state. And the type a should be moved from the ref to the state parameter. I think this gives us statically safe polymorphic refs. And I forgot some parentheses in newRef. I think these are the right types: newRef :: a -> (exists s . (Ref s, ^st s a :: State)) readRef :: (?st s a :: State) => Ref s -> a writeRef :: Ref s -> a -> ((), ^st s a :: State) -- Ben