小编use*_*427的帖子

将n行读入[String]

我正在尝试将内容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)

haskell

10
推荐指数
1
解决办法
4578
查看次数

无法从此表达式派生(显示)

此代码不起作用

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

5
推荐指数
1
解决办法
329
查看次数

标签 统计

haskell ×2