On Sat, 22 Dec 2007 22:41:37 -0500, Neil Mitchell <[EMAIL PROTECTED]> wrote:

Hi

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.

With the class context in the BST definition, ghc gives no complaints when I evaluate "Empty":

*BST> Empty
Empty
*BST> :t Empty
Empty :: BST a

I assume I misunderstand you.

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.

I see what you mean here. To get ghc to accept my code (where BST is Foldable), I omit the class context from the data definition, but add the Ord class context to the signatures of the BST functions that require it (insert, for example).

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.

Thanks

Neil

Thanks!

Brad

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to