如何在Haskell中为网格创建坐标

时间:2016-02-29 16:52:39

标签: haskell grid

我试图定义一个函数grid :: Int -> [(Int,Int)],它返回一个n×n方格上所有(x,y)坐标对的列表。

    grid :: Int -> [(Int,Int)]
    grid x y = [x y| |(x <- [1..x] y <- [1..y])]

GHCi告诉我

    parse error on input ‘<-’
    Perhaps this statement should be within a 'do' block?
Failed, modules loaded: none.
Prelude>

1 个答案:

答案 0 :(得分:1)

这是你想要做的吗?

 grid n = [(x, y)| x<- [0..n], y<-[0..n]]