解析错误(可能是不正确的缩进)
我收到以下错误,任何人都可以解释一下代码有什么问题吗?
105:0: parse error (possibly incorrect indentation)
这是代码:
-- Type inference for expressions
--
tyInf :: Gamma -> Exp -> TC (Exp, Type, Subst)
tyInf g (Num n) = return (Num n, intTyCon, [([intId], intTyCon)])
tyInf g (Con tag[])
| tag == unitTag = return (Con tag[],unitTyCon,[([unitId], unitTyCon)])
| tag == falseTag = return (Con tag[], boolTyCon, [([boolId],boolTyCon)])
| tag == trueTag = return (Con tag[],boolTyCon, [([boolId],boolTyCon)])
| otherwise = error "unknown constructor"
tyInf g (Con tag [ e1, e2]) | tag == pairTag = do
return ( (Con tag [ e1, e1], (mkPairTy (tyInf g e1) (tyInf g e2)),
[([pairId], (mkPairTy (tyInf g e1) (tyInf g e2)))])
-- ---------------------------------------------------------------------
-- The type for a unifier. A value of this type maps free
-- type variables to real types.
--
-- You may change this type if you wish. The following is
-- one possible type, though not necessarily the best.
--
type Subst = [([TyVar], Type)] -- <--- This is line 105
-- --------------------------------------------------------------------
-- Unification
--
unify :: Type -> Type -> Subst
unify t1 t2
| t1 == t2 = []
| otherwise = [(tyVarsIn t1, t2)]
I am getting following error can any one explain me what is wrong with the code.
105:0: parse error (possibly incorrect indentation)
This is the code:
-- Type inference for expressions
--
tyInf :: Gamma -> Exp -> TC (Exp, Type, Subst)
tyInf g (Num n) = return (Num n, intTyCon, [([intId], intTyCon)])
tyInf g (Con tag[])
| tag == unitTag = return (Con tag[],unitTyCon,[([unitId], unitTyCon)])
| tag == falseTag = return (Con tag[], boolTyCon, [([boolId],boolTyCon)])
| tag == trueTag = return (Con tag[],boolTyCon, [([boolId],boolTyCon)])
| otherwise = error "unknown constructor"
tyInf g (Con tag [ e1, e2]) | tag == pairTag = do
return ( (Con tag [ e1, e1], (mkPairTy (tyInf g e1) (tyInf g e2)),
[([pairId], (mkPairTy (tyInf g e1) (tyInf g e2)))])
-- ---------------------------------------------------------------------
-- The type for a unifier. A value of this type maps free
-- type variables to real types.
--
-- You may change this type if you wish. The following is
-- one possible type, though not necessarily the best.
--
type Subst = [([TyVar], Type)] -- <--- This is line 105
-- --------------------------------------------------------------------
-- Unification
--
unify :: Type -> Type -> Subst
unify t1 t2
| t1 == t2 = []
| otherwise = [(tyVarsIn t1, t2)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 105 之前的代码行快速复制并粘贴到执行语法高亮显示的编辑器中,显示您的语法不会相加。试试这个:
注意末尾额外的
)
。您确实应该投入一些时间来设置您的开发环境。它得到了回报。
A quick copy and paste of the line of code prior to 105 into an editor that does syntax hilighting shows your parans do not add up. Try this:
Note the extra
)
at the end.You really should invest some time into setting up your development environment. It pays off.