typing query

Amit Garg amitji@cs.utexas.edu
Fri, 21 Feb 2003 01:12:28 -0600 (CST)


Hey all.

I am trying to declare a read-only state monad and a read-write state
monad, so as to distinguish between methods on a data type that are
read-only vs. read-write.

This is the best I could come up with:

newtype ST s a = ST ( s -> (s,a) ) -- read-only
newtype SW s a = SW ( s -> (s,a) ) -- read-write

class ReadM m s a where
    readM :: m s s
    runM :: s -> m s a -> (a,s)

class WriteM m r s where
    updateM :: (s -> s) -> m s ()

instance ReadM ST s a where
    readM = ST (\s -> (s,s))
    runM s (ST c) = c s -- Doesn't work

instance ReadM SW s a where
    readM = SW (\s -> (s,s))
    runM s (SW c) = c s -- Doesn't work

And later on ...
    updateM s (SW c) = c s

Does that make sense? If not, how do I do it? If so, is there a
simpler means of getting there? Thanks.

;Amit
-------------------------------------------------------------------
Amit Garg                      |  Office:  ACES 6SEo4E
Graduate Student               |  Phone :  (512) 232-7875
Computer Sciences              |  Res   :  2000 Pearl St. #209
University of Texas at Austin  |  Phone :  (512) 659-2532
           Homepage: http://www.cs.utexas.edu/~amitji
-------------------------------------------------------------------