我的代碼是這樣的:實例聲明哈斯克爾
type Code = [Inst]
data Inst = PUSH Int
| PUSHV Name
| POP Name
| DO Op
| JUMP Label
| JUMPZ Label
| LABEL Label
deriving Show
doJump :: Inst -> Code -> Code
doJump l c = case (elemIndex l c) of
Just n -> drop (n+1) c
Nothing -> c
而且GHC返回我這個錯誤,這讓我完全難倒... 我試圖做的是從後點返回列表發生特定元素。
No instance for (Eq Inst) arising from a use of `elemIndex'
Possible fix: add an instance declaration for (Eq Inst)
In the expression: (elemIndex l c)
In the expression:
case (elemIndex l c) of {
Just n -> drop (n + 1) c
Nothing -> c }
In an equation for `doJump':
doJump l c
= case (elemIndex l c) of {
Just n -> drop (n + 1) c
Nothing -> c }
任何想法?
不要在Haskell使用標籤。他們沒有顯着的縮進工作。 – rightfold
@rightfold反對在Haskell中使用標籤,但[這不是其中之一](http://dmwit.com/tabs)。 –