# type classes / ghci

**Keean
**
k.schupke@ic.ac.uk

*Wed, 10 Jul 2002 10:43:53 +0100*

I have found what is either a problem in ghc/ghci or a problem in my
understanding...
either way if someone could point out whats wrong I would be very grateful.
I am experimenting with monad-transformers, and am tying to define a class
to allow a
run function to be overloaded. The program layers two monads on top of the
IO monad,
a state monad-transformer, and an error monad-transformer.
If I define a set of untyped functions:
unFC (FC x) = x -- run a forward composed monad
unBC (BC x) = x -- run a backward composed monad
unSTM (STM x) = x -- run a monad composed with a State monad-transformer
I then used ghci to derive the type for these functions...
unFC :: forall m n a . (Monad m,Monad n) => FComp m n a -> n (m a)
unBC :: forall m n a . (Monad m,Monad n) => BComp m n a -> m (n a)
unSTM :: forall s m a . (Monad m) => StateT s m a -> s -> m (a,s)
the program still passes type checking with these types added.
next I defined a type class:
class Composed c where
run :: c
and some instances:
instance (Monad m,Monad n) => Composed (FComp m n a -> n (m a))
run = unFC
instance (Monad m,Monad n) => Composed (BComp m n a -> m (n a))
run = unBC
instance (Monad m) => Composed (StateT s m a -> s -> m (a,s))
run = unSTM
However when I compile now, replacing:
unFC (unSTM test (0::Int))
with
run (run test (0::Int))
I now get an error: no instances for (Composed (t -> IO t1),Composed (StateT
Int ErrorIO Int -> Int -> t))
Regards,
Keean.