While reading "Learn You a Haskell for Great Good!" I came across the YesNo type class<br><br>I tried a minimal version as below<br><br>module Kind where<br><br>class Yesno a where<br> yesno :: a -> Bool<br>
<br>instance Yesno Int where<br> yesno 0 = False<br> yesno _ = True<br><br><br>I was surprised to get an error<br><br>*Kind> :load kind.hs<br>[1 of 1] Compiling Kind ( kind.hs, interpreted )<br>Ok, modules loaded: Kind.<br>
*Kind> yesno 10<br><br><interactive>:1:6:<br> Ambiguous type variable `t' in the constraints:<br> `Num t' arising from the literal `10' at <interactive>:1:6-7<br> `Yesno t' arising from a use of `yesno' at <interactive>:1:0-7<br>
Probable fix: add a type signature that fixes these type variable(s)<br><br>Turns out 10 in this instance is an Integer and I have not defined Yesno over Integer<br><br>Easy fix - just define an instance over Integer<br>
<br clear="all">instance Yesno Integer where<br>
yesno 0 = False<br>
yesno _ = True<br>
<br>My question - Is there a way to avoid this kind of boilerplate? What is the idiomatic way?<br><br>Thanks & Regards,<br>Amitava Shee<br><br>