<div dir="ltr">Hi,<div><br></div><div>I am writing a sample code below and getting an error. Please help to resolve it:</div><div><br></div><div>Code:</div><div>
<p class="gmail-p1"><span class="gmail-s1">import Data.List</span></p>
<p class="gmail-p2"><span class="gmail-s1"></span><br></p>
<p class="gmail-p1"><span class="gmail-s1">findLoot val [] = </span><span class="gmail-s2">0.0</span></p>
<p class="gmail-p1"><span class="gmail-s1">findLoot val ((x:y:[]):xs) | val == </span><span class="gmail-s2">0</span><span class="gmail-s1"> = </span><span class="gmail-s2">0.0</span></p>
<p class="gmail-p1"><span class="gmail-s1"> | val < y = ((fromIntegral val) * (fromIntegral x)) / fromIntegral y</span></p>
<p class="gmail-p1"><span class="gmail-s1"> | val > y = ((div val y)*x) + (findLoot (mod val y) xs)</span></p><p class="gmail-p1"><span class="gmail-s1"><br></span></p><p class="gmail-p1"><span class="gmail-s1">Error:</span></p><p class="gmail-p1"><span class="gmail-s1">No instance for (Fractional a0) arising from a use of ‘it’</span></p><p class="gmail-p1"><span class="gmail-s1"> The type variable ‘a0’ is ambiguous</span></p><p class="gmail-p1"><span class="gmail-s1"> Note: there are several potential instances:</span></p><p class="gmail-p1"><span class="gmail-s1"> instance HasResolution a => Fractional (Fixed a)</span></p><p class="gmail-p1"><span class="gmail-s1"> -- Defined in ‘Data.Fixed’</span></p><p class="gmail-p1"><span class="gmail-s1"> instance Integral a => Fractional (Ratio a)</span></p><p class="gmail-p1"><span class="gmail-s1"> -- Defined in ‘GHC.Real’</span></p><p class="gmail-p1"><span class="gmail-s1"> instance Fractional Double -- Defined in ‘GHC.Float’</span></p><p class="gmail-p1"><span class="gmail-s1"> ...plus one other</span></p><p class="gmail-p1"><span class="gmail-s1"> In the first argument of ‘print’, namely ‘it’</span></p><p class="gmail-p1"><span class="gmail-s1">
</span></p><p class="gmail-p1"><span class="gmail-s1"> In a stmt of an interactive GHCi command: print it</span></p><p class="gmail-p1"><span class="gmail-s1"><br></span></p><p class="gmail-p1"><span class="gmail-s1">Sample Input and Output:</span></p><p class="gmail-p1"><span class="gmail-s1"></span></p><pre class="gmail-lang-hs gmail-prettyprint gmail-prettyprinted" style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:normal"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit"><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">Input </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">1</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:-</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
val </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">50</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">((</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">x</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">y</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:[]):</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">xs</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[[</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">120</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">30</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">],</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">50</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">],[</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">60</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">20</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]]</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
Output </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">1</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:-</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">180.0000</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
Input </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">2</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:-</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
val </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">10</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">((</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">x</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">y</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:[]):</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">xs</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[[</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">500</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">30</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]]</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
Output </span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">2</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">:-</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-lit" style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">166.6667</span></code></pre></div></div>