<div dir="auto"><div dir="auto">Because:</div>(!!) :: [a] -> Int -> a</div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 17, 2017 5:50 AM, "Peter Normington" <<a href="mailto:peter@ireby.org.uk">peter@ireby.org.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Why do I get an error in the following example:<br><br><span style="font-family:monospace,monospace">memoized_fib :: Integer -> Integer<br>memoized_fib = (map fib [0 ..] !!)<br> where fib 1 = 1<br> fib 2 = 1<br> fib n = memoized_fib (n-2) + memoized_fib (n-1)</span><br><br></div>but not in:<br><div><br><span style="font-family:monospace,monospace">memoized_fib :: Int -> Integer<br>memoized_fib = (map fib [0 ..] !!)<br> where fib 1 = 1<br> fib 2 = 1<br> fib n = memoized_fib (n-2) + memoized_fib (n-1)</span></div><div>?</div><div><br></div><div>The error is reported by GHCi as:</div><div><br></div><div><span style="font-family:monospace,monospace">error:<br> • Couldn't match type ‘Integer’ with ‘Int’<br> Expected type: Integer -> Integer<br> Actual type: Int -> Integer<br> • In the expression: (map fib [0 .. ] !!)<br> In an equation for ‘memoized_fib’:<br> memoized_fib<br> = (map fib [0 .. ] !!)<br> where<br> fib 1 = 1<br> fib 2 = 1<br> fib n = memoized_fib (n - 2) + memoized_fib (n - 1)<br> |<br>2 | memoized_fib = (map fib [0 ..] !!)<br> | ^^^^^^^^^^^^^^^^^<br>Failed, 0 modules loaded.<br></span></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div></div>