You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Haskell代码触发parse error缩进或括号不匹配错误如何解决

问题原因

你的代码触发语法解析错误的核心原因是guard守卫语法书写错误:

  • 你在otherwise分支后遗漏了必须的等号=,Haskell要求所有守卫分支都遵循| 条件 = 表达式的固定格式
修正后的完整代码
type Nat0                = Int
type Zeichenreihe        = String
type Teilzeichenreihe    = String
type IstTeilzeichenreihe = Bool
type Zerlegungszeuge     = (Zeichenreihe,Zeichenreihe,Zeichenreihe)
type Zerlegungszeugen    = [Zerlegungszeugen]


-- Aufgabe A.1

ist_tzr :: Zeichenreihe -> Teilzeichenreihe -> IstTeilzeichenreihe


ist_tzr _ [] = True
ist_tzr [] _ = False
ist_tzr (x:xs) (y:ys)
 | x == y = ist_tzr xs ys
 | otherwise = ist_tzr xs (y:ys) 
语法补充说明
  • Haskell中otherwise本质是值为True的常量,属于守卫条件的一部分,必须和其他守卫分支保持相同的书写格式,不能省略等号
  • 缩进错误、括号不匹配也会触发同类报错,排查时可以优先检查函数分支、守卫、where/let块的格式是否规范

内容的提问来源于stack exchange,提问作者Horozovic Maida

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 20:54:05