Skip to content

Added Huffman with Haskell #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged

Conversation

jiegillet
Copy link
Member

Added Haskell implementation, and fixed a few typos and trailing spaces in huffman.md.

The main issue with the code is that (to simplify implementation) the tree generated can have some branches inverted compared with the algorithm from the video. The bit length doesn't change at all, so it's not a huge deal, maybe.

Thoughts?

import qualified Data.Map as M
import Data.List (insert, sort)

data Tree a = Nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to have Nil? It seems better not to support implicitly nullability.

where toSortedList = sort . map swap . M.toList
swap (a, i) = (i, a)

buildTree :: (Ord a) => [a] -> Tree a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then this would just return a Maybe (Tree a)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, why not ^^

@jiegillet
Copy link
Member Author

Switched to a Maybe (Tree a) on ubsan's suggestion.

@leios
Copy link
Member

leios commented Apr 18, 2018

This one also looks good to merge, unless there are outstanding problems.

@leios leios merged commit 823b071 into algorithm-archivists:master Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants