小编Wol*_*lfe的帖子

使用Haskeline的getInputLine输入

我有代码

 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                                     
Run Code Online (Sandbox Code Playgroud)

进程具有类型定义

process :: [String] -> IO ()
Run Code Online (Sandbox Code Playgroud)

但是我得到错误:

• 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 $ …
Run Code Online (Sandbox Code Playgroud)

monads haskell haskeline

4
推荐指数
1
解决办法
179
查看次数

Haskell-使用从createProcess和CreatePipe创建的句柄通过管道传递到StdStream

我目前有以下代码:

main :: IO ()                                                                       
main = do                                                                           
    (_, Just so, _, _)  <- createProcess (proc "ls" ["."]) { std_out = CreatePipe } 
    _ <- createProcess (proc "sort" []) { std_in = so }                             
    print "foo"     
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

 Couldn't match expected type ‘StdStream’                 
         with actual type ‘GHC.IO.Handle.Types.Handle’
 In the ‘std_in’ field of a record                        
 In the first argument of ‘createProcess’, namely         
   ‘(proc "sort" []) {std_in = so}’                       
 In a stmt of a 'do' block:                               
   _ <- createProcess ((proc "sort" []) {std_in …
Run Code Online (Sandbox Code Playgroud)

haskell process

3
推荐指数
1
解决办法
299
查看次数

如何比较char和escape终端转义序列

如果我有这样的事情:

main :: IO ()                    
main = do                        
    hSetBuffering stdin NoBuffering
    c <- getChar                   
Run Code Online (Sandbox Code Playgroud)

我将如何比较c,看看我是否有一个转义序列,如箭头键或ctrl加一个键.

谢谢

haskell term

2
推荐指数
1
解决办法
95
查看次数

标签 统计

haskell ×3

haskeline ×1

monads ×1

process ×1

term ×1