user3648942
user3648942

Reputation: 1

Debugging huffman decoding

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

Answers (1)

Piotr Miś
Piotr Miś

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

Related Questions