huffman encoding exercise

8 views
Skip to first unread message

Francesco Lazzarino

unread,
May 24, 2011, 1:32:54 PM5/24/11
to gainesvil...@googlegroups.com
i think i'm beyond the point of no return when i get frustrated with other langs to implement an algorithm. its just oo easy in haskell, even with my noobness.

i've got a basic huffman codec and want to improve the haskellness of it. can you guys take a look?


lines 49+ are me just making some test data to play with

some thing i'm wondering about:
  • i'm declaring Ord a => .... all over the place, is there a way to factor it out of let the compiler derive it?
  • lines 17,18, is there a better way to do it?
  • is there a recursion patter that i could use on codeTree instead of doing the recursion myself? same with decode?
  • i know how to hlint, but how do i profile it?
  • can i make Tree a an instance of Functor and make the trav function cleaner? or maybe use the Writer monad?
  • how can i bitpack in haskell?
  • how can i make this take advantage of multiple cores? i think there are lots of good candidates but don't know where to start.
  • to be of any use the code table needs to be outputted with the bits, is there a good marshaling module in haskell?
quickCheck issues:
  • quickCheck (\s -> (length $ encode (codex s) s) < (length s)) blows up when passing it [] and [()], how do i debug this?
  • is there a canonical way to put multiple quickChecks in a file for a suite? is it as simple as just rolling your own with something like mapM_ over all the tests?
thanks in advance guys

Ian Taylor

unread,
Jun 13, 2011, 11:43:06 PM6/13/11
to gainesvil...@googlegroups.com

Hey, I worked on this some.

Hopefully this will help with a few of the things you were wondering
about. I used binary-strict to pack [Bool] into ByteString and
vice-versa.

https://gist.github.com/1024266

Francesco Lazzarino

unread,
Jun 14, 2011, 12:16:38 AM6/14/11
to gainesvil...@googlegroups.com
wow, i'll go in more depth tomorrow, thanks for this, expect questions!
--
franco
Reply all
Reply to author
Forward
0 new messages