我是Haskell的新手,我试图从根跟踪二叉树中节点的路径。 我在SO中关注了这个链接: - Trying to implement path record for Haskell binary tree search
我修改了代码以便更好地理解
inTree:: Eq a => a -> Tree a -> Maybe [Direction]
inTree x End = Nothing
inTree x (Node y l r ) = if (x == y) then Just [] else (fmap (L:) (inTree x (Node _ l _ )) <|> (fmap (R:) (inTree x (Node _ _ r))))
但是当我尝试编译它时出现以下错误: -
Not in scope: ‘<|>’
Perhaps you meant one of these:
‘<$>’ (imported from Prelude), ‘<*>’ (imported from Prelude)
任何人都可以帮我解决这个问题
此外,任何人都可以在上面的代码中解释3rd line
。
什么是L:
,什么是R:
?
编辑 -
阅读完评论后,我尝试使用case construct
,但我遇到了以下错误: -
inTree:: Eq a => a -> Tree a -> Maybe [Direction]
inTree x End = Nothing
inTree x (Node y l r ) | x == y = Just [] | l\=Empty = L:(inTree x l)
错误Couldn't match expected type ‘Maybe Direction’ with actual type ‘[Maybe Direction] -> [Maybe Direction]