我遇到了错误:
> Levels.hs:3:40: error:
parse error (possibly incorrect indentation or mismatched brackets)
|
3 | let screens = ["stage one","stage two"]
| ^
when I try to use a list I declared in a module called Levels
. Below is my main.hs
file:
import System.IO
import Levels
main = do
putStrLn (head Levels.screens)
以下是我的Levels.hs
module Levels where
let screens = ["stage one","stage two"]
请问为什么我会收到此错误?
let
is only for declaring variables within some scope – the scope of a function or a monadic block. Basically what it does is, it creates a new top-level environment in which you can then declare variables.But when writing a source file, you're already at the top level, so you don't need to (and in fact, can't) use
let
.像这样写出来
...最好还添加一个类型签名
Where you could use
let
is if you needed some helper definitions for implementing that list, like或者,就像通常写的那样,
Note that when using
let
in GHCi, likeyou're already in a scope, namely an implicit
do
block of theIO
monad, i.e. this is like