简体   繁体   English

Haskell:不在范围内:数据构造函数

[英]Haskell: Not in scope: data constructor

Started to learn haskell today for school and I run into a problem with function. 今天开始学习haskell for school,我遇到了功能问题。 I don't understand why it's not in the scope.. 我不明白为什么它不在范围内..

Heres the code: 下面是代码:

ff :: [[Char]] -> [[Char]] -> [Char]
ff A B = [[x !! 0, y !! 1] | x <- A, y <- B, (x !! 1) == (y !! 0)]

And errors: 和错误:

md31.hs:2:4: Not in scope: data constructor `A'

md31.hs:2:6: Not in scope: data constructor `B'

md31.hs:2:38: Not in scope: data constructor `A'

md31.hs:2:46: Not in scope: data constructor `B'

Thanks in advance :) 提前致谢 :)

Function parameters have to start with a lowercase letter in Haskell. 函数参数必须以Haskell中的小写字母开头。

As such, you'd need to make A and B lowercase ( a and b ) in your function definition. 因此,您需要在函数定义中创建AB小写( ab )。

If the first letter of an identifier is in uppercase, it is assumed to be a data constructor . 如果标识符的第一个字母是大写的,则假定它是数据构造函数

In Haskell the capital letters mean that value is data constructor as in: 在Haskell中,大写字母表示值是数据构造函数,如下所示:

data Test = A | B

If you need variable use lowercase: 如果你需要变量使用小写:

ff a b = [[x !! 0, y !! 1] | x <- a, y <- b, (x !! 1) == (y !! 0)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM