3
data Peg = Red | Green | Blue | Yellow | Orange | Purple
    deriving (Show, Eq, Ord)

type Code = [Peg]

data Move = Move Code Int Int
      deriving (Show, Eq)

isConsistent :: Move -> Code -> Bool
isConsistent (move1 code1 num1 num2) code2 = True --parse error here

Relatively new to Haskell. Wondering why I receive the following error message after attempting to load this.

Parse error in pattern: move1

1 Answer 1

8

move1 isn't a data constructor (which is what you're allowed to pattern match on) and in fact it can't be since they have to start with uppercase letters. Replace it with the constructor Move from your data declaration and the error should go away.

You will probably still get some warnings like "code1 defined but not used" you can get rid of them by changing the pattern to (Move _ _ _) if you really don't care about the contents.

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

1 Comment

Note that if you need a value to refer to the entire piece being pattern matched on, precede it with a name@, ex: move1@(Move code int1 int2). move1 now refers to the entire Move.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.