Here's my contrived example that threw the error. If you go into ghci, and do a `:t (foo' "blah" myDoohickey)`, you will get the type signature "IO ()". Doing the same for myOtherDoohickey returns "IO True" So you would think that you'd be able to uncomment the code that makes IO an instance of Toplevel. foo' is a function that allows IO to run monadic values of type Doohickey. But it doesn't work. --- import IO import Control.Monad.Reader class (Monad n) => Doohickey n where putRecord :: String -> n () class (Monad m) => Toplevel m where foo :: (Doohickey n) => FilePath -> n a -> m a newtype IOToplevelT a = IOToplevelT { runIOToplevelT :: ReaderT Handle IO a } deriving (Monad, MonadReader Handle, MonadIO) instance Doohickey IOToplevelT where putRecord = liftIO . putStrLn foo' s k = do f <- liftIO $ openFile s AppendMode runReaderT (runIOToplevelT k) f --instance Toplevel IO where -- foo = foo' myDoohickey = do putRecord "foo" putRecord "bar" myOtherDoohickey = do putRecord "hello" putRecord "world" return True On Mon, Apr 13, 2009 at 7:55 PM, Jason Dusek <jason.dusek@gmail.com> wrote:
Copypasting and loading your code doesn't throw an error. Please, pastebin an example that demonstrates the error.
-- Jason Dusek