haskell的新手,我需要为每个单独的项目打印出单独一行中包含的数据
不确定如何
type ItemDescr = String
type ItemYear = Int
type ItemPrice = Int
type ItemSold = Int
type ItemSales = Int
type Item = (ItemRegion,ItemDescr,ItemYear,ItemPrice,ItemSold,ItemSales)
type ListItems = [Item]
rownumber x
| x == 1 = ("Scotland","Desktop",2017,900,25,22500)
| x == 2 = ("England","Laptop",2017,1100,75,82500)
| x == 3 = ("Wales","Printer",2017,120,15,1800)
| x == 4 = ("England","Printer",2017,120,60,7200)
| x == 5 = ("England","Desktop",2017,900,50,45000)
| x == 6 = ("Wales","Desktop",2017,900,20,18000)
| x == 7 = ("Scotland","Printer",2017,25,25,3000)
showall
--print??
例如在每一行上 显示
“苏格兰”,“台式机”,2017,900,25,22500
下一条记录
答案 0 :(得分:0)
提示1:
像这样存储数据
items = [("Scotland","Desktop",2017,900,25,22500),
("England","Laptop",2017,1100,75,82500),
("Wales","Printer",2017,120,15,1800),
("England","Printer",2017,120,60,7200),
("England","Desktop",2017,900,50,45000),
("Wales","Desktop",2017,900,20,18000),
("Scotland","Printer",2017,25,25,3000)]
提示2:
实现此功能
toString :: Item -> String
toString = undefined -- do this yourselves
提示3:
尝试结合以下功能
unlines
,已经在前奏曲中toString
,您刚刚写了map
,不需要任何解释putStrLn
,甚至不确定这是否是实函数,但无论如何仍需要它。($)
,您可以不用这一项,但是会为您带来加分