[Haskell-beginners] fonction in a typeclass that does not mention the type variable

TP paratribulations at free.fr
Wed Aug 21 21:44:43 CEST 2013


Peter Hall wrote:

> Maybe I don't fully understand what you are trying to achieve, but I don't
> think what you are trying to do makes sense. infixLevel and
> symbolToConstructor will have different implementations for each instance
> of Foo, and the compiler cannot possibly know which implementations you
> mean.

Indeed, my question was stupid. This is obvious in the second implementation 
(which instance to choose?), and it is also true in the first one because 
even if symbolToInfixLevel of one considered instance uses infixLevel and 
symbolToConstructor of this same instance (what I am not sure of), at the 
location where I use this function the compiler cannot known which instance 
I mean.

> If the implementation of symbolToInfixLevel is independent of the
> implementations of infixLevel and symbolToConstructor then it shouldn't
> need them in its definition.

No, they are not independent: it is really a function that "composes" 
functions infixLevel and symbolToConstructor. See my proposition in my 
answer to Peter Jones.






More information about the Beginners mailing list