Haskell Not in Scope: Enter the constructor or class `PushInt '

I have my own data type that states:

data Commands = MoveLeft |
                MoveRight |
                MoveUp |
                MoveDown |
                IfVertical |
                IfHorizontal |
                InputChar |
                InputInt |
                OutputChar |
                OutputInt |
                OutputNewline |
                PushInt Int |
                Add |
                Sub |
                Mult |
                Div |
                Exp |
                Pop |
                Dup |
                Switch |
                Noop |
                End
                deriving (Show, Eq)

and I have a function with which I am trying to extract a number from PushIntwith:

extractNum :: PushInt -> Int
extractNum (PushInt n) = n

But when I try to run this, I get an error message:

Parser.hs:32:19:
    Not in scope: type constructor or class `PushInt'
    A data constructor of that name is in scope; did you mean -XDataKinds?

As far as I knew, I was allowed to retrieve a field from the data using this method. I am sure this is just a very simple mistake, but any help is appreciated.

+4
source share
1 answer

Wow, I was right around 2am. Function

extractNum :: PushInt -> Int
extractNum (PushInt n) = n

it should be

extractNum :: Commands -> Int
extractNum (PushInt n) = n
+9
source

All Articles