Reputation: 1
While I was debugging my huffman decoding function
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
it comes up with a parse error on input "where"? Where did I do wrong?
Upvotes: 0
Views: 191
Reputation: 981
The real problem with this code is in fact mismatched parenthesis - not the indentation in case expression. Also, there are arrows instead of =
sign in helper functions.
The following code parses fine.
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
Upvotes: 2