<div dir="ltr">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. <span style="font-family:arial,sans-serif;font-size:13px">infixLevel and </span><span style="font-family:arial,sans-serif;font-size:13px">symbolToConstructor </span><span style="font-family:arial,sans-serif;font-size:13px">will have different implementations for each instance of Foo, and </span><span style="font-family:arial,sans-serif;font-size:13px">the compiler cannot possibly know which implementations you mean. If the implementation of </span><span style="font-family:arial,sans-serif;font-size:13px">symbolToInfixLevel is independent of the implementations of </span><span style="font-family:arial,sans-serif;font-size:13px">infixLevel and </span><span style="font-family:arial,sans-serif;font-size:13px">symbolToConstructor then it shouldn't need them in its definition.</span><div>
<span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Peter</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 21 August 2013 17:39, TP <span dir="ltr"><<a href="mailto:paratribulations@free.fr" target="_blank">paratribulations@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I have a simple test case containing a typeclass Foo with one type variable<br>
a. The goal is to write once and for all a function symbolToInfixLevel<br>
function that combines two other functions defined in the typeclass:<br>
<br>
-----------------------<br>
class Foo a where<br>
<br>
symbolToConstructor :: String -> ( a -> a -> a )<br>
infixLevel :: a -> Int<br>
<br>
symbolToInfixLevel :: String -> Int<br>
symbolToInfixLevel s = infixLevel $ (symbolToConstructor s) undefined<br>
undefined<br>
-----------------------<br>
<br>
This yields an error because there is no "a" in the type signature for<br>
symbolToInfixLevel:<br>
<br>
$ runghc test_typeclass_without_typevariable.hs<br>
test_typeclass_without_typevariable.hs:1:1:<br>
The class method `symbolToInfixLevel'<br>
mentions none of the type variables of the class Foo a<br>
When checking the class method: symbolToInfixLevel :: String -> Int<br>
In the class declaration for `Foo'<br>
<br>
Now, if I define symbolToInfixLevel out of the typeclass:<br>
<br>
-----------------------<br>
class Foo a where<br>
<br>
symbolToConstructor :: String -> ( a -> a -> a )<br>
infixLevel :: a -> Int<br>
<br>
symbolToInfixLevel :: String -> Int<br>
symbolToInfixLevel s = infixLevel $ (symbolToConstructor s) undefined<br>
undefined<br>
-----------------------<br>
<br>
Now, I obtain:<br>
<br>
$ runghc test_typeclass_without_typevariable.hs<br>
test_typeclass_without_typevariable.hs:7:24:<br>
No instance for (Foo a0) arising from a use of `infixLevel'<br>
In the expression: infixLevel<br>
In the expression:<br>
infixLevel $ (symbolToConstructor s) undefined undefined<br>
In an equation for `symbolToInfixLevel':<br>
symbolToInfixLevel s<br>
= infixLevel $ (symbolToConstructor s) undefined undefined<br>
<br>
How to get rid from this situation?<br>
<br>
Thanks in advance,<br>
<br>
TP<br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>