Haskell...模块解析错误
Haskell... parse error on module
这有什么问题吗?我尝试了多种解决方案,但最终都以 '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,并确保正确地缩进
这有什么问题吗?我尝试了多种解决方案,但最终都以 '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,并确保正确地缩进