[Haskell-cafe] Defining types (newbie)

Bryan O'Sullivan bos at serpentine.com
Wed Mar 14 03:14:46 EDT 2007

John Fouhy wrote:

> But if I want to combine tcEqOne and tcGtThree I run into type
> problems, because one of them uses Strings and the other Integers.

Yep.  The observation you can make here is that TC is really a fancy way 
to write a function that takes some parameters and returns a Bool.  So 
And and Or don't really care what types their parameters have, so long 
as they return Bools when evaluated.

If you could get rid of the type variable on the left, you'd be set, 
because then And and Or would each take ThingCompares of any type.  And 
you can!  See section 7.3.4 of the Hugs manual for "existential types": 

This will let you move your type variable a into the TC branch alone as 
"forall a. TC ...", so it will not, er, infect the rest of the branches 
of the type.  Then And and Or will neither care, nor be able to find 
out, about what TC really has inside, which is as you might wish.


More information about the Haskell-Cafe mailing list