[Haskell-cafe] A Foldable binary search tree

Neil Mitchell ndmitchell at gmail.com
Sat Dec 22 22:41:37 EST 2007


> data (Ord a) => BST a = Empty | BST (BST a) a (BST a)

Experience has taught me to _never_ put class contexts on data
definitions. Now you can't write something as simple as "Empty" - you
have to give it a class context. This is just plain annoying.

I would accept this pain if it meant I could write:

insert :: a -> BST a -> BST a

and have the Ord silently inserted - but you can't. You still have to
write the Ord a => explicitly.

As a result, I see no advantage to adding the class constraint, and
plenty of disadvantages. If there are some advantages to this context
I would be interested to know what they are.



More information about the Haskell-Cafe mailing list