哈斯克尔..模块上的分析错误



这有什么问题?我尝试了多种解决方案,但最终都在"module"和main后面的=符号中出现错误。怎么了?!?!?!

printTabuleiro :: [[Char]] -> IO()
printTabuleiro [] = []
printTabuleiro (l :lt) = putStr l : printTabuleiro lt
module Main where
main = let 
          a = ["#####n","###o##n"] 
       in do printTabuleiro a

现在我收到了这个编译错误,我不理解这里的类型匹配问题。顺便说一句,我还很新,不习惯工作。请不要把我弄到火星上。

[1 of 1] Compiling Main             ( visualisacao.hs, interpreted )
visualisacao.hs:14:27:
    Couldn't match expected type ‘IO ()’ with actual type ‘[IO ()]’
    In the expression: putStr l : printTabuleiro lt
    In an equation for ‘printTabuleiro’:
        printTabuleiro (l : lt) = putStr l : printTabuleiro lt
visualisacao.hs:14:38:
    Couldn't match expected type ‘[IO ()]’ with actual type ‘IO ()’
    In the second argument of ‘(:)’, namely ‘printTabuleiro lt’
    In the expression: putStr l : printTabuleiro lt
Failed, modules loaded: none.

您需要首先声明您的模块。然后你需要申报你的进口产品。然后您可以定义自己的功能。

module声明前面只能有注释和编译器杂注(如语言扩展)。把module Main where行放在文件的顶部,把它下面的所有内容都放在上面。导入还必须介于模块声明和任何函数或类型声明之间,所以它看起来应该像

module Main where
import Data.Char
import ...
printTabuleiro :: ...
printTabuleiro [] = ...
main = let
         a = ...
    in do printTabuleiro a

IIRC,我的问题是缩进不正确(严重!)确保您使用的是三个空格而不是一个TAB,并确保正确地对进行了子索引

相关内容

  • 没有找到相关文章