Peter Normington peter at ireby.org.uk
Sun Dec 17 16:15:37 UTC 2017

```Thanks, Theodore.  As simple as that!
Best regards,
Peter

On 17 December 2017 at 15:40, Theodore Lief Gannon <tanuki at gmail.com> wrote:

> Because:
> (!!) :: [a] -> Int -> a
>
> On Dec 17, 2017 5:50 AM, "Peter Normington" <peter at ireby.org.uk> wrote:
>
>> Why do I get an error in the following example:
>>
>> memoized_fib :: Integer -> Integer
>> memoized_fib = (map fib [0 ..] !!)
>>   where fib 1 = 1
>>         fib 2 = 1
>>         fib n = memoized_fib (n-2) + memoized_fib (n-1)
>>
>> but not in:
>>
>> memoized_fib :: Int -> Integer
>> memoized_fib = (map fib [0 ..] !!)
>>   where fib 1 = 1
>>         fib 2 = 1
>>         fib n = memoized_fib (n-2) + memoized_fib (n-1)
>> ?
>>
>> The error is reported by GHCi as:
>>
>> error:
>>     • Couldn't match type ‘Integer’ with ‘Int’
>>       Expected type: Integer -> Integer
>>         Actual type: Int -> Integer
>>     • In the expression: (map fib [0 .. ] !!)
>>       In an equation for ‘memoized_fib’:
>>           memoized_fib
>>             = (map fib [0 .. ] !!)
>>             where
>>                 fib 1 = 1
>>                 fib 2 = 1
>>                 fib n = memoized_fib (n - 2) + memoized_fib (n - 1)
>>   |
>> 2 | memoized_fib = (map fib [0 ..] !!)
>>   |                 ^^^^^^^^^^^^^^^^^
>>
>>
>> _______________________________________________
>> Beginners mailing list