list - 在 Haskell 中打印列表 new
问题描述
全新的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
接下来是下一条记录
解决方案
提示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
,甚至不确定这是否是一个真正的功能,但无论如何你都需要它。($)
,你可以不用这个,但它会给你加分
推荐阅读
- php - 未找到列:1054 'on 子句中的未知列 'locations.id'
- model-view-controller - 控制器或服务的责任?
- awk - 输出中间的换行符
- javascript - React esLint 错误:缺少数组中元素的“key”道具
- python - 高斯滤镜只会使图像变暗,不会模糊
- docker - 'stderr: remove /etc/passwd' 在构建 Docker 容器时
- reactjs - React intl 模板字符串抛出一个错过的 id 警告
- tfs - TFS 2018 和 AppCenter 测试
- yaml - Yaml : yaml 文件中的格式错误。预期的 '
',但发现' - single-sign-on - Apereo CAS分两步加载用户属性并存储起来进行属性发布