[英]How to generate a list with own data type in haskell
I am trying to create an infinite list with my own data type in haskell 我正在尝试在Haskell中使用我自己的数据类型创建一个无限列表
data Color = Black | White deriving (Show, Eq)
data Cell = Empty | Stone Color deriving (Show, Eq)
makeRow :: Int -> Row
makeRow 0 = []
makeRow n = take n (repeat Cell Empty)
And it gives me the error : 它给了我错误:
Data constructor not in scope: Cell
You get this error because Cell
is - indeed - not a value constructor. 您会收到此错误,因为Cell
实际上-不是值构造函数。 Just use plain Empty
instead (note that you don't write Bool True
or Bool False
- you just write True
or False
). 只需使用普通的Empty
(请注意,您不会写Bool True
或Bool False
,而只是写True
或False
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.