Parse error in Haskell

2

I am new to Haskell and also in programming. I'm trying to learn Haskell with exercises already done.

Just now I get an error that says the following.

  

error: parse error on input "n", failed modules load: none

From the following code

 listaMatriz :: Num a => [[a]] -> Matriz a
    listaMatriz xss = listArray ((1,1),(m,n)) (concat xss)
           where m = length xss
                 n = length (head xss)

What do you think is the problem? I can not identify it.

    
asked by Alan Erick Salgado Vazquez 22.10.2016 в 01:10
source

2 answers

0

It's a problem of indentation. In Haskell, indentation defines where a block of code begins and ends. Everything you want to define within where must have an indentation greater than this.

listaMatriz :: Num a => [[a]] -> Matriz a
listaMatriz xss = listArray ((1,1),(m,n)) (concat xss)
    where
        m = length xss
        n = length (head xss)

On the other hand, although it is not usual, you can use keys {} and semicolons ; to define the blocks independently of the indentation:

listaMatriz :: Num a => [[a]] -> Matriz a
listaMatriz xss = listArray ((1,1),(m,n)) (concat xss)
    where {
        m = length xss;
        n = length (head xss)
    }

You can find more information about these common errors in the wiki .

    
answered by 22.10.2016 / 13:33
source
0

The problem is in the second line (it should start at the same height as the first one), where is well indented.

listaMatriz :: Num a => [[a]] -> Matriz a
listaMatriz xss = listArray ((1,1),(m,n)) (concat xss)
       where m = length xss
             n = length (head xss)
    
answered by 16.11.2016 в 20:41