0

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The proposed solution is nice, but the explanation of what went wrong is not correct. data GameTree2 = Start | GameTreeNode does not expand at all; it simply defines a new name GameTreeNode at the term level that is completely distinct from the GameTreeNode that exists at the type level.
@DanielWagner oh my, what an oversight on my part.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.