解析错误(可能是不正确的缩进)

发布于 2024-12-11 23:01:55 字数 1334 浏览 0 评论 0原文

我收到以下错误,任何人都可以解释一下代码有什么问题吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2024-12-18 23:01:55

将 105 之前的代码行快速复制并粘贴到执行语法高亮显示的编辑器中,显示您的语法不会相加。试试这个:

 return ( (Con tag [ e1, e1], (mkPairTy (tyInf g e1) (tyInf g e2)),
      [([pairId], (mkPairTy (tyInf g e1) (tyInf g e2)))]))

注意末尾额外的 )

您确实应该投入一些时间来设置您的开发环境。它得到了回报。

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:

 return ( (Con tag [ e1, e1], (mkPairTy (tyInf g e1) (tyInf g e2)),
      [([pairId], (mkPairTy (tyInf g e1) (tyInf g e2)))]))

Note the extra ) at the end.

You really should invest some time into setting up your development environment. It pays off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文