2014-09-03 77 views
4

我有我自己的數據類型,指出:哈斯克爾不在範圍內:類型構造函數或類`PushInt」

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) 

,我有一個功能,與我試圖從PushInt提取數搭配:

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

但是當我嘗試運行此,我得到一個錯誤,指出:

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? 

至於我知道我是允許使用此方法從數據中提取字段。我很確定這只是一個非常簡單的錯誤,但任何幫助表示讚賞。

回答

9

哇,是我對一個凌晨2點的錯誤。功能

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

應該

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