Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. stringBuilder :: Tree -> [Char] -> [Char]
  2. stringBuilder t s = snd (decode t s [])
  3.  
  4. -- Take the current tree, the current input string, and the current output
  5. -- string, return the remainder of the inpupt string and the modified output
  6. -- string
  7. decode :: Tree -> [Char] -> [Char] -> ([Char], [Char])
  8. decode (Leaf c)     i      o = (i, o ++ [c]) -- You only need one case here
  9. decode (Branch a b) (i:is) o =    
  10.     case i of
  11.         '0' -> decode a is o
  12.         '1' -> decode b is o
  13.         _   -> undefined
  14. decode (Branch a b) []     o = ([], o)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement