Pergunta

Here is my code:

-- combine lists with binary operation

clwbo :: (Num a, Num b, Num c) => (a -> b -> c) -> [a] -> [b] -> [c] 
clwbo fps lista listb
    |length lista /= length listb = []
    |length lista ==length listb = case lista listb of
                                       [] [] -> []
                                       x:xs y:ys -> [fps x y] ++ clwbo fps xs ys
                                       otherwise -> error "get off"

And here is the error message from terminal:

test.hs:8:42: Parse error in pattern: xs
Failed, modules loaded: none.

Anyone likes to tell me what's wrong with my code?

Foi útil?

Solução

You cannot put multiple patterns side by side like that in a case expression. To match multiple patterns at once, put them in a tuple:

case (lista, listb) of
   ([], [])     -> ...
   (x:xs, y:ys) -> ...
   otherwise    -> ...
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top