哈斯克尔.哪里有两个定义

Iam*_*Man 3 haskell

有两种方法可以使用两个或更多块的'where'吗?像这样的东西:

plus:: Int -> Int -> Int
plus a b = x + y
         where x = f1 a
         where y = f2 b
Run Code Online (Sandbox Code Playgroud)

dav*_*420 15

除了第一个以外的所有内容where:

plus:: Int -> Int -> Int
plus a b = x + y
         where x = f1 a
               y = f2 b
Run Code Online (Sandbox Code Playgroud)

注意

  • 定义必须相互排列
  • 你应该使用空格只,而不是标签缩进定义(某些文本编辑器不使用的标签标准的标签宽度,导致GHC相信最后一行进一步以下缩进比实际的;无论哪种方式会导致错误)

  • 我想建议一个关于where语法的简短易读:http://learnyouahaskell.com/syntax-in-functions#where. (2认同)