我试图定义一个函数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>
答案 0 :(得分:1)
这是你想要做的吗?
grid n = [(x, y)| x<- [0..n], y<-[0..n]]