1

I have a haskell file, sum.hs, that reads:

sum' :: (Num a) => [a] -> a
sum' [] = 0
sum' (x:xs) = x + sum' xs

This works as expected within ghci by loading the module in.

However, if I try to declare the function within ghci I get an error:

Prelude> sum' [] = 0
Prelude> sum' (x:xs) = x + sum' xs
Prelude> sum' [3,4]
*** Exception: <interactive>:2:1-25: Non-exhaustive patterns in function sum'

Please can someone explain why loading the module in works but declaring the function within ghci results in this error?

laker93
  • 498
  • 4
  • 9

0 Answers0