Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Not in Scope: Type 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'm trying to extract the number from the PushInt with:

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

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

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 extract a field from data with this method. I'm pretty sure that this is just a really simple mistake, but any help is appreciated.

like image 882
Aearnus Avatar asked Jan 09 '23 22:01

Aearnus


1 Answers

Wow, was I right about a 2 am mistake. The function

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

should be

extractNum :: Commands -> Int
extractNum (PushInt n) = n
like image 73
Aearnus Avatar answered Jan 25 '23 21:01

Aearnus