I would like to create a new data type that either takes in Start or A tuple of values. This is what I have:
type Coord = (Int, Int)
data Direction = N | E | S | W
deriving (Eq, Show, Read)
type Move = (Coord, Direction)
type BoardSpec = [(Coord, Bool)]
type GameTreeNode = (GameTree2, BoardSpec, Move)
data GameTree2 = Start | GameTreeNode deriving(Show)
blahblah :: GameTree2
blahblah = blahb
blahb :: GameTreeNode
blahb = (Start, testbo, ((1, 1), N))
This however, gives me the error on blahblah
Couldn't match type `(GameTree2, Move)' with `GameTree2'
Expected type: GameTree2
Actual type: GameTreeNode
data GameTree2 = Start |
GameTreeNode deriving(Show)
expands to:
data GameTree2 = Start | (GameTree2, BoardSpec, Move) deriving(Show)
You can't make a tuple a valid value of your type.
You need to wrap it in a constructor:
data GameTree2 = Start | Node GameTreeNode deriving(Show)
where Node
is whatever name you choose for it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.