-1
我正在尝试从this tutorial的程序。该方案是这样的:有人可以告诉我输入应该如何去?
type Name = String
type PriceInCents = Int
type ShoppingListItem = (Name, PriceInCents)
type ShoppingList = [ShoppingListItem]
shoppingList :: ShoppingList
shoppingList = [ ("Bananas", 300)
, ("Chocolate", 250)
, ("Milk", 300)
, ("Apples", 450)
]
sumShoppingList :: ShoppingList -> PriceInCents
sumShoppingList [] = 0
sumShoppingList (x:xs) = getPriceFromItem x
+ sumShoppingList xs
getPriceFromItem :: ShoppingListItem -> PriceInCents
getPriceFromItem (_, price) = price
main :: IO()
main = putStrLn ("Price of shopping list is "
++ show (sumShoppingList shoppingList)
++ " cents.")
我试图运行它,并没有错误,但我不知道该怎么输入。我试过了,但我想我错了,因为我得到这个错误:
ERROR - Undefined data constructor
任何人都可以告诉我,我应该输入什么?
所以也许我问的是错的?我用英文解释不好,但是当我运行这个程序时,我应该输入什么来使它完成它的工作? Idk如果我有道理 – Mel
你能准确描述你是如何得到这个错误的吗?您的代码在编译时生成正确的输出(通过编译为可执行文件或将文件加载到'GHCi'中,然后调用'main')。 – hnefatl