处理一个给定 SuffixTree 作为输入的函数,输出该后缀树中的整数列表。例如。getIndices tree1 = [2,4,1,3,5,0] 。整数列表的顺序无关紧要。我在函数的倒数第二行收到错误:“ Couldn't match expected type 'SuffixTree' with actual type '[SuffixTree]'
”。我已经考虑了很长时间,但没有运气。任何帮助将不胜感激。
data SuffixTree = Leaf Int | Node [ ( String, SuffixTree ) ]
deriving (Eq,Ord,Show)
text1 :: String
text1 = "banana"
tree1 :: SuffixTree
tree1 = Node [("banana",Leaf 0),
("a",Node [("",Leaf 5),
("na",Node [("",Leaf 3),
("na",Leaf 1)])]),
("na",Node [("",Leaf 4),
("na",Leaf 2)])]
------------------------------------------------------------------
getIndices :: SuffixTree -> [ Int ]
getIndices sufTree = getIndices' sufTree []
where getIndices' :: SuffixTree -> [Int] -> [Int]
getIndices' (Node ((_, Node xs):ys)) c
| Node xs == Node [] = c
| otherwise = getIndices' ((Node xs):([Node ys])) c
getIndices' (Node ((_,Leaf i):xs)) c = getIndices' (Node xs) (i:c)