Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Indentation 缩进在这里扮演什么角色?为什么一个缩进没有';不行?_Indentation_Haskell - Fatal编程技术网

Indentation 缩进在这里扮演什么角色?为什么一个缩进没有';不行?

Indentation 缩进在这里扮演什么角色?为什么一个缩进没有';不行?,indentation,haskell,Indentation,Haskell,下面是RWH手册中的一个示例程序。我想知道为什么第一个很好,但是第二个甚至不能编译?唯一的区别是第一个选项卡在之后使用了2个选项卡,其中mainWith func=do,而第二个选项卡仅使用1个选项卡。不知道这意味着什么?为什么第二个无法编译?还有为什么do construct可以为空 非常感谢, 亚历克斯 ——真实世界Haskell示例代码第4章: -- http://book.realworldhaskell.org/read/functional-programming.html 导入Sy

下面是RWH手册中的一个示例程序。我想知道为什么第一个很好,但是第二个甚至不能编译?唯一的区别是第一个选项卡在
之后使用了2个选项卡,其中mainWith func=do
,而第二个选项卡仅使用1个选项卡。不知道这意味着什么?为什么第二个无法编译?还有为什么
do construct
可以为空

非常感谢, 亚历克斯

——真实世界Haskell示例代码第4章:
-- http://book.realworldhaskell.org/read/functional-programming.html
导入System.Environment(getArgs)
与func input output=do交互
s putStrLn“错误:需要两个参数”
myFunction=id
--以下代码有编译错误
--%ghc--使与.hs交互
--[1/1]编译Main(interactiwith.hs,interactiwith.o)
-- 
--interactivewith.hs:8:26:空的'do'构造
导入System.Environment(getArgs)
与func input output=do交互
s putStrLn“错误:需要两个参数”
myFunction=id

do-块不能为空,这就是为什么会出现错误。当只使用一个选项卡
args时,
main with
函数的定义缩进到第10列:

    where mainWith func = do
          ^
从此行开始的
do
块的内容仅缩进到第8列:

        args <- getArgs
        case args of 
            ...
        ^

啊,哇,这太神秘了。谢谢你,这就解释了。没有预料到缩进在“where”之后开始。@Alex:这是因为
where
有自己的缩进级别(按预期从
w
开始)。您可以在一个
块中定义多个函数,其中
块。函数定义自启动自己的缩进级别,与
where
引入的缩进级别不同。
        args <- getArgs
        case args of 
            ...
        ^