Monad transformers question

Magnus Lindberg f98mali@dd.chalmers.se
Sun, 04 May 2003 20:06:32 +0200


--'ThIs-RaNdOm-StRiNg-/=_.683760939:
Content-Length: 2380
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
MIME-Version: 1.0

{-  Hi !
I have tried to write an "EnvState" monad transformer, but it is quite
useless because when a function peeks at the state but ignores the
environment (or vice versa) the code won't compile. GHC tells that the
monad I use is no instance of the MonadEnvState, but I really think it
is!
  An example:
( I attach the monad transformer file, MonadTrans2.hs, if someone
wonders how EnvStateT looks (I have only written EnvStateT myself, my
teacher has written the others some time ago (I think))  )
-}


import MonadTrans2


data Env   = Env Int
data State = State Int


type M = EnvStateT Env State IO

f, g, h :: M ()


f = do (Env e, State s) <- getES    -- This works since I show GHC
       return ()                    --   exactly what Env and State I
use ?

g = do State s <- getS          -- compile time error!
       return ()

h = do Env e <- getE            -- compile time error!
       return ()


{-
I have already told Haskell that the monad M uses an `Env' and a
`State' (the `type M = ...') so why does GHC complain? The function
`g' gives:

    No instance for (MonadEnvState (EnvStateT Env State IO) e State)
    arising from use of `getS' at envstate.hs:33
    In a 'do' expression pattern binding: State x <- getS
    In the definition of `g':
        do
          State x <- getS
          return ()
          
This means that my environment-state monad is nearly useless, since
all functions have to use both the state and the environment in order
to compile. I thought the following could solve the problem:

instance MonadEnvState M Env State

since I then tell Haskell that M is an instance of MonadEnvState, but
then the code won't compile: 
    
    Illegal instance declaration for `MonadEnvState M Env State'
        (The instance type must be of form (T a b c)
         where T is not a synonym, and a,b,c are distinct type 
         variables)
    In the instance declaration for `MonadEnvState M Env State'
    
Does anyone know what to do? Is this a problem with Haskell without
any solution? Must one perhaps first make a state monad and then
transform the state monad into an environment monad? Can't one have
both a state and an environment in one single monad at the same time
without these compiler errors?

Thanks for any help !

Best regards, Magnus Lindberg
-}
--'ThIs-RaNdOm-StRiNg-/=_.683760939:
Content-Length: 15062
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream;name=MonadTrans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