小编Gag*_*gan的帖子

我正在尝试重新定义haskell中的产品定义.我收到一条错误说"函数中的非详尽模式"

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)

recursion haskell pattern-matching

2
推荐指数
1
解决办法
66
查看次数

标签 统计

haskell ×1

pattern-matching ×1

recursion ×1