Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell, Even though my type is not specified I get this error: Couldn't match type `a' with `[a]', `a' is a rigid type variable bound by
    text
    copied!<p>So I realize this is a possible duplicate question, as there a number of those errors reported on Stack Overflow, but none of the solutions seem to apply to my problem.</p> <p>So I have the following function:</p> <pre><code>elementAt' :: Integral b =&gt; [a] -&gt; b -&gt; a elementAt' [x:_] 1 = x elementAt' [x:xs] y = elementAt' xs yminus1 where yminus1 = y - 1 </code></pre> <p>In case you're wondering it's problem 3 from <a href="http://haskell.org/haskellwiki/H-99%3a_Ninety-Nine_Haskell_Problems">99 Haskell Problems</a>. The goal of the function is to take as input a list and an index, and return the value at that index (starting at 1). I don't want a solution to the problem, if I did I could just look at the ones provided. But I'm getting an error I don't understand. I'm using eclipseFP, the eclipse plugin for haskell and it's underlining the "[x:_]" and "[x:xs]" portions of the function with the following error:</p> <pre><code>Couldn't match type `a' with `[a]' `a' is a rigid type variable bound by the type signature for elementAt' :: Integral b =&gt; [a] -&gt; b -&gt; a </code></pre> <p>In all the threads that discuss this error that I've looked at the problem usually occurs when someone tries to give an incorrect output to something which expects a certain type. For example, returning the length of something (which is of type Int) to what should be a "Num a" variable type.</p> <p>But in my case I'm not even providing a type for variable a. It should be able to be ANYTHING, right? So why am I getting this error? If I understood why I was getting the error I could fix it, but I just don't understand.</p> <p>Could someone please explain to me why I'm receiving this error?</p> <p>Your help is much appreciated, thank you. -Asaf</p> <p>Edit: Every answer provided so far is correct, thank you all for the helpful information. I'm going to pick the one I believe to be most clear (I have to wait 5 minutes to do it though).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload