<div dir="ltr"><div><div>What is the difference between these two type declarations? The second one is wrong but I can't convince myself why it should be wrong. Is it because <i>Int </i>not a constraint class and it is only an instance of one? My curiousity is why #1 can't be written in the form of #2. I apologise if I am using wrong terminology as type, class and constraint class are used with not much distinction. To add context, this problem is to find a function that will find an element by passing in a list and an index argument.<br><br>elementAt''' ::[a]-> Int ->a -- #1</div><div>elementAt''' [] _= error "list is empty"</div><div>elementAt''' list index </div><div><span style="white-space:pre">   </span>| (index < 1) = error "index has to be positive number"</div><div><span style="white-space:pre">  </span>| otherwise= list !! (index-1)</div></div><div><br></div><div><div>elementAt'''' ::(Int b)=>[a]-> b ->a -- #2</div><div>elementAt'''' [] _= error "list is empty"</div><div>elementAt'''' list index </div><div><span style="white-space:pre">  </span>| (index < 1) = error "index has to be positive number"</div><div><span style="white-space:pre">  </span>| otherwise= list !! (index-1)</div></div><div><br></div><div>Thank you. I just began learning Haskell. </div><div><br></div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Yours sincerely,</div><div>Justin</div><div><br></div><div><em>I check my email at 9AM and 4PM everyday</em></div><div><em>If you have an <strong>EMERGENCY</strong>, contact me at +447938674419(UK) or +60125056192(Malaysia)</em>  </div><div><br></div></div></div></div></div></div></div></div>
</div>