Problem with Infinite Lists

Wamberto Vasconcelos wvasconc@csd.abdn.ac.uk
Wed, 3 Sep 2003 09:30:18 +0100


Folks

I am new in this forum, so apologies if this has been asked before. If this is 
the case, please point me to the direction of the answer and I won't bother you 
again!

Also, could you make sure you CC your answers to me? I am not sure how long it 
takes for my subscription to be activated and I don't want to miss out on the 
action :-)

The Problem

I have defined this function to calculate the Fibonacci numbers:

all_fib :: [Float]

all_fib = 1:(1:(add_fib all_fib))
          where add_fib (x:y:rs) = (x + y):(add_fib (y:rs))

Which seems to work:

Main> take 20 all_fib
[1.0,1.0,2.0,3.0,5.0,8.0,13.0,21.0,34.0,55.0,89.0,144.0,233.0,377.0,
 610.0,987.0,1597.0,2584.0,4181.0,6765.0]

However, when I tried 

Main> filter even (take 20 all_fib)
ERROR - Illegal Haskell 98 class constraint in inferred type
*** Expression : filter even (take 20 all_fib)
*** Type       : Integral Float => [Float]

What is going on here?

Thanks in advance for any help/hint.

-- 
Wamberto Vasconcelos, PhD          wvasconcelos@acm.org
Department of Computing Science    http://www.csd.abdn.ac.uk/~wvasconc
University of Aberdeen, Aberdeen AB24 3UE, Scotland, UK
Phone +44 (0)1224 272283           Fax +44 (0)1224 273422