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
相关产品推荐
相关产品推荐

