3

Started to learn haskell today for school and I run into a problem with function. 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 :)

Trac3
  • 270
  • 3
  • 13
  • As noted in the answers the variable names need to be lowercase. The official documentation related to this is at http://www.haskell.org/onlinereport/intro.html#namespaces – Chris Kuklewicz Nov 04 '11 at 15:17

2 Answers2

7

Function parameters have to start with a lowercase letter in Haskell.

As such, you'd need to make A and B lowercase (a and b) in your function definition.

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

Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118
6

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

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)]
Maciej Piechotka
  • 7,028
  • 6
  • 39
  • 61