[英]Invalid argument hGetContents in Haskell
I'm trying to sort a list of ints and print them out, but am receiving this exception: 我正在尝试对整数列表进行排序并打印出来,但是却收到此异常:
Exception: <stdin>: hGetContents: invalid argument (Bad file descriptor)
The program: 该程序:
import Data.List
main :: IO ()
main = do
interact maxTri
putStrLn ""
readInt :: String -> Int
readInt = read
maxTri :: String -> String
maxTri = show .
sort .
map readInt .
words
interact
(semi-)closes the input stream. interact
(半)关闭输入流。 This does not play well if you are in ghci, which expects to continue using the input stream. 如果您使用的是ghci(希望继续使用输入流),则此方法不能很好地发挥作用。
Compile and run your program with 使用以下命令编译并运行程序
ghc path.hs
path
and this problem should not appear. 并且该问题不应出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.