我正在尝试将内容n行读入字符串列表.我已尝试过以下代码的几种变体,但没有任何效果.
main = do
input <- getLine
inputs <- mapM getLine [1..read input]
print $ length input
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
Couldn't match expected type `a0 -> IO b0'
with actual type `IO String'
In the first argument of `mapM', namely `getLine'
In a stmt of a 'do' block: inputs <- mapM getLine [1 .. read input]
In the expression:
do { input <- getLine;
inputs <- mapM getLine [1 .. read input];
print $ length input }
Run Code Online (Sandbox Code Playgroud)
和
main = …Run Code Online (Sandbox Code Playgroud) 此代码不起作用
data Expression = Atom String
| Sequence [Expression]
deriving (show)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
$ runghc bug.hs
ghc: panic! (the 'impossible' happened)
(GHC version 7.4.1 for x86_64-apple-darwin):
nameModule show{tv a9J}
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Run Code Online (Sandbox Code Playgroud)
我做错了什么,或者它确实是一个错误?
haskell ×2