3

I have problem with n+k pattern.

I want to enable it, but i don't know how.

I have added {-# LANGUAGE NPlusKPatterns #-} at the beggining of my .hs file, but it didn't work.

Also I try typping in my ghci console -NPlusKPatterns but is just gives me errors.

4

1 回答 1

5

你需要输入

:set -XNPlusKPatterns

在 ghci 中启用它们。

为了完整起见,我会指出,如果您从命令提示符加载 ghci 而不是运行winghci,则可以使用ghci -XNPlusKPatterns而不是交互式地加载它:set -XNPlusKPatterns

您可以通过交互定义 n+k 模式来检查它是否有效。这是一个示例会话:

Prelude> let fact 0 = 1; fact (n+1) = (n+1)*fact n in fact 5
<interactive>:8:23: Parse error in pattern: n + 1

Prelude> :set -XNPlusKPatterns
Prelude> let fact 0 = 1; fact (n+1) = (n+1)*fact n in fact 5
120
于 2013-05-11T17:41:01.393 回答