Huffman code generator in Haskell
Specify imports

Do you know the names of all functions in Data.List? Me neither. Specify what you import like

import Data.List (delete)


In my final version, this becomes

import Data.List (minimumBy,partition)
import Data.Ord (comparing)


Ord vs Eq

Your Ord and Eq instances do not agree! For Ord, only the frequency matters, for Eq, both frequency and payload have to be equal. This leads to oddities like this:

&gt; let i c x = Internal (Leaf c 0) (Leaf ' ' 0) x -- helper
&gt; i 'a' 1 &gt;= i 'b' 1
False
&gt; i 'b' 1 &gt;= i 'b' 1
True


To solve the issue, I'd get rid of the Ord instance by

where mf = minimumBy (comparing freq) list


Use deriving

You implement a custom Eq instance for Tree, where deriving Eq would suffice. It takes a second to figure out what deriving Eq does, to read yours takes longer and does nothing different.

use pattern matches

length and indexing with !! 0 look like a direct translation from imperative programming. Use pattern matching instead:

treeBuilder []   = error "Empty"
treeBuilder [x]  = x
treeBuilder list = treeBuilder $ collapseLowest list


The use of length causes an unnecessary traversal of the list and can cause performance issues: In the worst case you lose list fusion.

Getting rid of Eq constraint

Just as minimumBy allowed to get rid of the Ord instance, deleteBy allows to get rid of the Eq constraint.

extractMinFreq list = (mf , deleteBy ((==) `on` freq) mf list)


Now you can compress uncomparable things like functions or IO actions after Char has been replaced by a.

Eta reduction

leafMap allows eta reduction, the lambda can be written with uncurry. (The latter is of dubious value)

 leafMap = map (uncurry Leaf)


Github

You can see all steps at https://github.com/Frank-Siebert/codereview86061