Use Haskeline login getInputLine

I have a code

 main :: IO()
 main = runInputT defaultSettings loop          
 where                                        
   --loop :: InputT IO ()                     
   loop = do                                  
     minput <- getInputLine "$ "              
     case minput of                           
       Nothing -> return ()                   
       Just input -> process $ words input          
     loop                                     

If the process has a type definition

process :: [String] -> IO ()

However, I get the error message:

• Couldn't match type ‘IO’ with ‘InputT m’                                                       
Expected type: InputT m ()                                                                     
  Actual type: IO ()                                                                           In the expression: process $ words input                                                       
In a case alternative: Just input -> process $ words input                                     
In a stmt of a 'do' block:                                                                     
  case minput of {                                                                             
    Nothing -> return ()                                                                       
    Just input -> process $ words input }

I was wondering if anyone could explain what I am doing wrong. I just want the original input from getInputLine to do other things.

thank

+4
source share
1 answer

All statements in a block domust have the same type (well, they must have the same monad in their type). In your case, this is InputT IO something(with a monad InputT IO).

getInputLine "$ "has a type InputT IO (Maybe String), so the part is fine.

case, , . - return (), InputT IO (). .

process $ words input. IO (), InputT IO (), .

: , ( "" ) IO x InputT IO x, liftIO:

Just input -> liftIO (process $ words input)

liftIO :: IO a -> InputT IO a ( , : liftIO :: (MonadIO m) => IO a -> m a, ).

+6

Source: https://habr.com/ru/post/1663077/


All Articles