1

What does "Non-exhaustive patterns in function scalarNew" mean in this context?

scalarNew :: [Integer]->[Integer]->Integer
scalarNew (x:xs) (y:ys) 
     | (length xs == length ys) = x * y + scalarNew xs ys
     | otherwise = error "error"
Al.G.
  • 4,327
  • 6
  • 31
  • 56
liu fish
  • 13
  • 4

1 Answers1

5

You have to add the base case when using recursion. In this situation, the base case is when both are empty lists.

scalarNew :: [Integer] -> [Integer] -> Integer
scalarNew []     []        = 0
scalarNew []     (y:ys)    = error "error"
scalarNew (x:xs)    []     = error "error"
scalarNew (x:xs) (y:ys) 
  | length xs == length ys = x * y + scalarNew xs ys
  | otherwise = error "error"

edit: handle only-one-empty-list case

lsmor
  • 4,698
  • 17
  • 38