Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonadException instance is not deduced

Tags:

haskell

Maybe I'm doing something stupid here, but I'm getting:

No instance for (MonadException Ti)
  arising from a use of `getInputLine'

in the code sample:

module Foo where
import System.Console.Haskeline
import System.Console.Haskeline.MonadException
import Control.Monad.State
import Control.Monad.IO.Class

type Ti = StateT Int IO

action :: String -> Ti ()
action s = do
    n <- get
    lift $ putStrLn $ show n ++ ": " ++ s

repl :: InputT Ti ()
repl = do
    minput <- getInputLine "?"
    case minput of
        Nothing    -> return ()
        Just input -> lift (action input) >> repl

Now, System.Console.Haskeline.MonadException defines

MonadException IO
(MonadIO (StateT s m), MonadException m) => MonadException (StateT s m)

and Control.Monad.IO.Class:

MonadIO IO
MonadIO m => MonadIO (StateT s m)

So, shouldn't it deduce the instance for Ti automatically?

like image 432
user21338 Avatar asked Jun 05 '13 15:06

user21338


1 Answers

There is no instance for the Lazy state transformer, just the strict one. Use import Control.Monad.State.Strict.

like image 63
Thomas M. DuBuisson Avatar answered Sep 29 '22 07:09

Thomas M. DuBuisson