<div> </div>
<div>=======================================================================</div>
<div>module Test where</div>
<div>class Arg a where<br> pr :: a -> String</div>
<div>instance Arg Int where<br> pr _ = "i"</div>
<div>instance Arg Char where<br> pr _ = "c"</div>
<div>instance Arg a => Arg [a] where<br> pr _ = "[" ++ pr (undefined :: a) ++ "]" -- the type variable 'a' is interpreted as an unbound one.<br> -- (1) pr :: [a] -> String<br> -- (2) pr (_ :: [a]) = "[" ++ pr (undefined :: a) ++ "]"</div>
<div>=======================================================================</div>
<div> </div>
<div>Dear All,</div>
<div> </div>
<div>I got some problem when I try to compile the above program.</div>
<div><br>The problem is due to the presence of a type variable 'a' in the body of the last instance declaration.<br>How could I refer to the type variable of Arg [a] in the instance declaration?</div>
<div> </div>
<div>I tried these options<br> 1) by giving an explicit declaration for pr<br> 2) by giving a type signature to the argument of pr with -XPatternsSignatures</div>
<div> </div>
<div>The first option gives me back an error :<br> Misplaced type signature: pr :: [a] -> String<br> The type signature must be given where `pr' is declared</div>
<div> </div>
<div>The second option gives me an error:<br> Test.hs:21:12: Not in scope: type variable `a'</div>
<div> </div>
<div>Would anybody help me to understand this problem?</div>
<div> </div>
<div>Thanks in advance.</div>
<div> </div>
<div>Kwanghoon</div>