concatr ::Integer -> [[Integer]] -> [[Integer]]
concatr x (y) = [x] : y
concatr x (y:ys) = concatr x y: concatr x ys
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多这样的组合,我的头开始受伤.我究竟做错了什么?我只想在传入的列表的每个子列表中放入一个整数.
你可以使用这个map功能.
concatr :: Integer -> [[Integer]] -> [[Integer]]
concatr x ys = map (x:) ys
Run Code Online (Sandbox Code Playgroud)
Eta简化为简洁的解决方案:
concatr x = map (x:)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
815 次 |
| 最近记录: |