Haskell错误变量不在范围内

时间:2017-12-15 11:37:20

标签: haskell emacs

我编写了一个非常基本的递归函数,但是当我尝试使用它时,Haskell给了我一个错误。

这是代码:

 {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "project": {
        "name": "xyz"
    },
    "apps": [
        {
            "root": "src",
            "outDir": "dist",
            "assets": [
                "assets",
                "favicon.ico"
            ],
            "index": "index.html",
            "main": "main.ts",
            "polyfills": "polyfills.ts",
            "test": "test.ts",
            "tsconfig": "tsconfig.app.json",
            "testTsconfig": "tsconfig.spec.json",
            "prefix": "app",
            "styles": [
                "assets/css/styles.css"

            ],
            "scripts": [
                "assets/js/project.js"      

            ],
            "environmentSource": "environments/environment.ts",
            "environments": {
                "dev": "environments/environment.ts",
                "prod": "environments/environment.prod.ts"
            }
        }
    ],
    "e2e": {
        "protractor": {
            "config": "./protractor.conf.js"
        }
    },
    "lint": [
        {
            "project": "src/tsconfig.app.json"
        },
        {
            "project": "src/tsconfig.spec.json"
        },
        {
            "project": "e2e/tsconfig.e2e.json"
        }
    ],
    "test": {
        "karma": {
            "config": "./karma.conf.js"
        }
    },
    "defaults": {
        "styleExt": "css",
        "component": {}
    }
}

这就是错误:

import Data.Char
import Test.QuickCheck
potencia :: Integer -> Integer -> Integer
potencia x 0 = 1
potencia x n = x*(potencia x (n-1))

如果我删除libreries的导入,它不再给我错误但我需要它们以供日后使用。我正在使用haskell平台的最新更新和emacs编辑器。 感谢。

1 个答案:

答案 0 :(得分:5)

I see you are defining your function in interactive shell. Most of Haskell's REPLs read and eval instructions line-by-line, so when you type >>> [int(prev < curr) for curr, prev in zip(data, chain((inf,), data))] [0, 1, 0, 0, 0, 1] it is interpreted right at this moment, so compiler complains that potencia is lacking implementation. You should either:

  • Define it in external file and load it using potencia :: Integer -> Integer -> Integer (recommended)
  • Type :l and use :set +m statement to define variable with respect to indentation
  • Surround your definition with let and :{
  • Put whole definition and declaration in one line separating each part with :}