<div dir="ltr"><div><div><div><div><div><div>While you may define this <i>Ord</i> instance by defining the <i>compare</i> method, you should probably not do this since <i>Ord</i> is supposed to follow some rules, in particular transitivity "<b>a < b and b < c means a < c</b>" is assumed but false in your case. Those rules are important for many functions to work correctly (sort, minimum, maximum and so on...).<br><br></div>You may simply define another function like <i>winAgainst</i> :<br><br></div><i>Rock `winAgainst` Scissors = True<br></i></div><i>Scissors `winAgainst` Paper = True<br></i></div><i>Paper `winAgainst` Rock = True<br>_ `winAgainst` _ = False<br></i><br></div>or maybe a <i>battle</i> function that returns a <i>Win | Loss | Tie</i>...<br><br></div>(NB : All functions can be used as infix by surrounding their name with ` (antiquotes))<br><div><div><div><div><div><div><div><div><div><br><div class="gmail_quote"><div dir="ltr">Le jeu. 30 juil. 2015 à 15:34, Nikita Danilenko <<a href="mailto:nda@informatik.uni-kiel.de">nda@informatik.uni-kiel.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Derek,<br>
<br>
you can find the desired functions and type classes using Hoogle [1].<br>
Your attempt at an Ord instance is basically the right idea, but you<br>
need to define the function "compare" only [2]. From your syntax it<br>
looks like you are trying to define a function called "ord" that<br>
additionally uses "compare" (in a way, it cannot be used). Removing<br>
"ord" in all three cases fixes your problem, although the resulting<br>
function "compare" is not total.<br>
<br>
The documentation of the type classes usually contains a description of<br>
what functions you need to define. The fact that the "Show" type class<br>
instance can be obtained using a function called "show" is a coincidence.<br>
<br>
Best regards,<br>
<br>
Nikita<br>
<br>
[1] <a href="https://www.haskell.org/hoogle/" rel="noreferrer" target="_blank">https://www.haskell.org/hoogle/</a><br>
<br>
[2] <a href="http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#t:Ord" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#t:Ord</a><br>
</blockquote></div></div></div></div></div></div></div></div></div></div></div>