At the end, I wrote:

> type Parser a = ReaderM (StateM [] String) Loc a
> type LocS     = [(Loc,String)]
> data Loc      = Loc { line, col :: !Int }

> item  :: Parser String
> item  =  do   x:_ <- update tail
>               return x

  This should have been:

> type Parser a = ReaderM (StateM [] LocS) Loc a
> type LocS     = [(Loc,Char)]
> data Loc      = Loc { line, col :: !Int }

> item  :: Parser Char
> item  =  do   (loc,x):_ <- update tail
>               ... -- do something interesting with loc
>               return x

  , the intent being that you are tracking the location.  OK, OK, in this case
the reader is useless, but I just wanted to test that the STM operations
lifted through the reader correctly.

  One other thing: you need overlapping instances to partially instantiate the
monad transformer so you can define things like:

> class (Monad m) => STM m where
>       update  :: (String -> String) -> m String
>       set     :: String -> m String
>       fetch   :: m String
>       set s   =  update (\_ -> s)
>       fetch   =  update id
                                      vvvvvv
> instance (Monad m) => STM (StateM m String) where
>       update f = StateM (\s -> return (s, f s))

  Sorry for this extra message.  (It's getting to be a bad habit with me...)

--------------------------------------------------------------------------
Frank Christoph                 Next Solution Co.       Tel: 0424-98-1811
[EMAIL PROTECTED]                              Fax: 0424-98-1500



Reply via email to