嗨,你能帮助我如何增加一个元组的最后一个元素。 目前,我有元组Haskell增加一个元组的最后一个元素
items :: [Grocery]
items = [("Water", "Drink Section", 1),
("Squash", "Drink Section", 1),
("Apple", "Fruit Section", 1),
("Plates", "Disposable Section", 1),
("Plates", "Ceramic Section", 1)]
和我想做的事是每1项是买的时间和输出数据库增加它的这个名单。目前我有这个
sales:: [database] -> String -> String-> [database]
sales db itemName sectionName = []
sales ((item, section, qty): xs) itemName sectionName
| item == itemName && section== sectionName = [(item, section, qty + 1)]
| otherwise = []
即时通讯仍然在增加它和im卡位。请帮助我,我仍然是这个语言的新手。谢谢!
编辑
所有现在的工作,但你怎么输出列表的休息吗?我试过recordSale xs trackArtist trackTitle
,但是当我测试它时,我增加的旧记录也被打印,而不是被修改?让说,我递增苹果是什么,它会打印是这
[("Apple", "Fruit Section", 2),("Water", "Drink Section", 1),("Squash", "Drink Section", 1), ("Apple", "Fruit Section", 1)]
它重复记录,而不是仅仅增加1
如果这是作业,请用[tag:homework]标签标记它。 *提示:*使用'map'或列表理解 – fuz 2012-07-07 18:51:00