{- 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 -}