【发布时间】:2014-04-29 13:17:48
【问题描述】:
所以我需要编写一个程序返回整数列表的乘积。这是我尝试做的。但是每次我在第 4 行的 = 符号上收到“解析错误”。
--product.hs
product :: [Integer] -> Integer
product [] = 1
product i f = foldl (*) 1 [i..f]
main = do
print "Please enter first number"
i <- readLn
print "Please enter second number"
f <- readLn
print "The result is:"
print (product i f)
我也试过
product (x:xs) = x * product xs
但它仍然给我在 = 符号上的解析错误
【问题讨论】:
-
什么是“整数列表的乘积”?我想你的意思是,列表中整数的乘积。
标签: list parsing haskell product