Advertisement
Kekker_

Untitled

Dec 10th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. stringBuilder :: Tree -> [Char] -> [Char]
  2. stringBuilder t s =
  3.     let c  = fst (decode t s)
  4.         xs = snd (decode t s)
  5.     in c ++ (stringBuilder t xs)
  6.  
  7. -- Recursively builds the output string by traversing
  8. -- the tree built in parse.
  9. decode :: Tree -> [Char] -> ([Char], [Char])
  10. decode (Leaf c)     (x:xs) = ([c], xs)
  11. decode (Leaf c)       []   = ([c], [])
  12. decode (Branch a b) (x:xs) =
  13.     if x == '0'
  14.         then decode a (x:xs)
  15.     else if x == '1'
  16.         then decode b (x:xs)
  17.     else undefined
  18. decode (Branch a b)   []   = ([], [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement