为什么模式匹配可以共享where子句?

时间:2016-12-14 01:17:50

标签: haskell syntax scope pattern-matching

我写了这个并且没有编译

import Data.Maybe
func Nothing Nothing = func2 "hello" "world"
func x       y       = func2 "hello" "world"
  where func2 a b = a ++ b
main = print $ func Nothing Nothing
test.hs:2:24: error:
    • Variable not in scope: func2 :: [Char] -> [Char] -> [Char]
    • Perhaps you meant ‘func’ (line 2)

我用守卫重写了它并且它起作用了。但我想知道为什么会这样。

0 个答案:

没有答案