typing query
Iavor S. Diatchki
diatchki@cse.ogi.edu
Fri, 21 Feb 2003 13:32:30 -0800
hi,
the read only "state" monad is usually called "environment", or "reader"
monad. since it is goind to be "read-only" there is no need to return a
new state in the result (as it would presumably be the same as the input
state). so the type becomes:
newtype Env e a = E (e -> a)
for something simillar to what you have take a look at
the Hugs/GHC monad transformer libraries, or at
www.cse.ogi.edu/~diatchki/MonadTransformers
bye
iavor
Amit Garg wrote:
> 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
> -------------------------------------------------------------------
>
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
--
==================================================
| Iavor S. Diatchki, Ph.D. student |
| Department of Computer Science and Engineering |
| School of OGI at OHSU |
| http://www.cse.ogi.edu/~diatchki |
==================================================