parsing - 在卫队haskell中使用case表达式时解析错误
问题描述
我是 Haskell 的新手,我遇到了语法问题。我想要做的是给定数据和这种数据类型的树,找到树中相应节点的路径。我相信我对该函数的逻辑是正确的,但我不知道如何使它成为有效的 Haskell。我尝试将制表符更改为空格。
-- | Binary trees with nodes labeled by values of an arbitrary type.
data Tree a
= Node a (Tree a) (Tree a)
| End
deriving (Eq,Show)
-- | One step in a path, indicating whether to follow the left subtree (L)
-- or the right subtree (R).
data Step = L | R
deriving (Eq,Show)
-- | A path is a sequence of steps. Each node in a binary tree can be
-- identified by a path, indicating how to move down the tree starting
-- from the root.
type Path = [Step]
pathTo :: Eq a => a -> Tree a -> Maybe Path
pathTo a End = Nothing
pathTo a (Node b l r)
| a == b = Just []
| case (pathTo a l) of
Just p -> Just [L:p]
Nothing -> case (pathTo a r) of
Just p -> Just [R:p]
Nothing -> Nothing
这是错误:
parse error (possibly incorrect indentation or mismatched brackets)
解决方案
推荐阅读
- image - QML 旋转图像未填充容器
- java - 尝试用 Java 制作 AI
- node.js - 使用 Framework7 和 service.js 在本地主机中托管时出错
- php - 将时间与 SQL 行关联
- python - 仅为少数字段添加 help_text。姜戈
- c++ - 人脸跟踪arduino代码优化
- android - 如何在 Dart\Flutter 中使用我的 JSON 响应
- css - 图像作为在 flexbox 中布局的链接
- android - 无法使用分页刷新 recyclerView
- elasticsearch - 更改任何 NON-INDEXED 字段的映射时,是否需要强制重新索引所有旧文档?