我正在调试我的霍夫曼解码功能
decode :: (Tree a, [Bit]) -> [a]
decode (tree, list) = case list of
[] -> case tree of
Leaf pos a -> replicate_Pos pos a
_ -> (num_only (follow_bit_path_to_one_value tree list)): huffman_decode (tree, (list_only (follow_bit_path_to_one_value tree list))
where
num_only :: (a, [Bit]) -> a
num_only (a, _) -> a
list_only:: (a, [Bit]) -> [Bit]
list_only (_, list) -> list
它在输入时出现了解析错误"其中"?我哪里做错了?
答案 0 :(得分:2)
这段代码的真正问题实际上是不匹配的括号 - 而不是case表达式中的缩进。此外,辅助函数中还有箭头而不是=
符号。
以下代码解析得很好。
decode :: (Tree a, [Bit]) -> [a]
decode (tree, list) = case list of
[] -> case tree of
Leaf pos a -> replicate_Pos pos a
_ -> (num_only (follow_bit_path_to_one_value tree list)): huffman_decode (tree, (list_only (follow_bit_path_to_one_value tree list)))
where
num_only :: (a, [Bit]) -> a
num_only (a, _) = a
list_only:: (a, [Bit]) -> [Bit]
list_only (_, list) = list