<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Indeed "Int b" is not a valid constraint: the kind of "Int" is
Type (or "*") as GHC reports:</p>
<p>> Expecting one fewer arguments to ‘Int’<br>
> Expected kind ‘* -> Constraint’, but ‘Int’ has kind ‘*’<br>
<br>
</p>
<p>A valid constraint would be "Int ~ b" as in the following
example. But I don't see why you would do this in this case,
especially if you are beginning with Haskell. It complicates the
code for no gain.<br>
</p>
<p>{-# LANGUAGE TypeFamilies #-}<br>
<br>
elementAt'''' ::(Int ~ b)=>[a]-> b ->a -- #2<br>
elementAt'''' [] _= error "list is empty"<br>
elementAt'''' list index <br>
| (index < 1) = error "index has to be positive number"<br>
| otherwise= list !! (index-1)<br>
</p>
<p><br>
</p>
<p>Cheers<br>
Sylvain<br>
</p>
<br>
<div class="moz-cite-prefix">On 28/03/2018 20:19, Justin Thong
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEtAGerrqzKtfwh5P=oVzJ98crqPVqUWcUp2hUg_j09k1d3JEQ@mail.gmail.com">
<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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</body>
</html>