product' :: [Integer] -> Integer
product' (x:xs)
| (x:xs) == [] = 1
| otherwise = x * (product' (xs))
Run Code Online (Sandbox Code Playgroud)
第一个不起作用并给出错误.下面的一个是使用模式匹配技术,并正常工作.
productP :: [Integer] -> Integer
productP [] = 1
productP (x:xs) = x * (productP (xs))
Run Code Online (Sandbox Code Playgroud)