有人知道如何在Haskell中生成一个网格吗? [英] Does anybody know how to generate a grid in Haskell?

查看:67
本文介绍了有人知道如何在Haskell中生成一个网格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是像以下2D列表:

[[1,2],[3,4]]

我想知道是否有任何方法可以使用:

  [1,2] 
[3,4]

或者类似的方式在行之间有一个硬入口,我可以引用列表中的元素作为索引i和j?

解决方案

很多方法可以做到这一点,但如果你现在正在做的话

$ p code print grid

尝试将其替换为

  mapM_ print grid 

分别打印每一行。


Instead of having a 2D list like:

[[1,2],[3,4]]

I was wondering if there is any way that you can have:

[1, 2]
[3, 4] 

Or something in the similar manner where there is a hard enter between rows and I can refer to an element in the list as index i and j?

解决方案

There are many ways to do this, but if you're currently doing

print grid

try replacing it with

mapM_ print grid

to print each row separately.

这篇关于有人知道如何在Haskell中生成一个网格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆