Haskell: not in scope: data constructor

I started studying haskell today for school, and I am having a problem with a function. I do not understand why this is not in the field.

Here is the code:

ff :: [[Char]] -> [[Char]] -> [Char] ff AB = [[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:)

+3
source share
2 answers

Function parameters must begin with a lowercase letter in Haskell.

Therefore, you must make A and B lowercase letters ( A and B ) in the definition of your function.

If the first letter of the identifier is uppercase, it is assumed to be a data constructor .

+7
source

In Haskell, capital letters mean that the value is a data constructor, as in:

 data Test = A | B 

If you need a variable, use lowercase letters:

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

All Articles