haskell - arising from a use of `Control.Exception.catch' -


when load haskell file, has error

module repl(repl(..), repl) import qualified control.exception e import system.console.readline(readline, addhistory)  data repl s = repl {     repl_init :: io (string, s),        -- prompt , initial state     repl_eval :: s -> string -> io (bool, s),       -- quit flag , new state     repl_exit :: s -> io ()     }  repl :: repl s -> io () repl p =     (prompt, state) <- repl_init p     let loop s = (do         mline <- readline prompt         case mline of         nothing -> loop s         line ->             (quit, s') <- repl_eval p s line             if quit             repl_exit p s'              else             addhistory line             loop s'         ) e.catch undefined (\(e :: e.someexception) -> putstrln "handled exception!"         )     loop state  repl.hs:21:5:     couldn't match expected type `io (maybe string)'            against inferred type `t -> maybe string'     in stmt of 'do' expression: mline <- readline prompt     in expression:         (do { mline <- readline prompt;               case mline of {                 nothing -> loop s                 line                   -> { (quit, s') <- repl_eval p s line;                           .... } } })           e.catch           undefined           (\ (e :: e.someexception) -> putstrln "handled exception!")     in definition of `loop':         loop s = (do { mline <- readline prompt;                        case mline of {                          nothing -> loop s                          line -> { ... } } })                    e.catch                    undefined                    (\ (e :: e.someexception) -> putstrln "handled exception!") 

use scoped type variables including line @ top of file:

{-# language scopedtypevariables #-} 

or in ghci session do:

> :set -xscopedtypevariables 

and in catch function provide signature. in ghci:

> import control.exception e > e.catch undefined (\(e :: e.someexception) -> putstrln "handled exception!") handled exception! 

celebrate times, come on!


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -