Type class inference trouble

Lars Lundgren lars@prover.com
Fri, 16 Feb 2001 09:52:41 +0100 (CET)

On Thu, 15 Feb 2001, Ken Shan wrote:

> Hello all,
> I'm trying to implement some simple natural language semantics with
> Haskell (Hugs), and I'm running into trouble with type classes.
> Here's what I want to do:  Suppose that
>     x :: a -> b
>     y :: a
> then I want to write
>     apply x y = x y :: b
> Moreover, if
>     x :: a
>     y :: a -> b
> I also want to write
>     apply x y = y x :: b

This is ad hoc overloading, and IMHO bad style, at least in haskell. As I
understand it, haskell type classes were never intended to support this. 

You will run into problems sooner or later if you think you can use type
classes to overload like you can in C++. 

Type classes are (as I understand it) (even with current
extensions) supposed to support a kind of less
ad hoc overloading where the arguments always play the same role.

/Lars L