Problem with Infinite Lists
Frank Seaton Taylor
Wed, 3 Sep 2003 14:18:00 -0400
This is a bit off topic, but...
Warning: contains evangelism from a number theorist.
The Fibonacci sequence should start with 0 and 1 rather than 1 and 1.
Doing so makes it adhere to the following property:
all_fib !! (gcd m n) == gcd (all_fib !! m) (all_fib !! n)
for m, n nonnegative integers. With the exception that Haskell
misdefines gcd 0 0 as an error rather than 0.
On Wednesday, Sep 3, 2003, at 04:30 US/Eastern, Wamberto Vasconcelos
> 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
> 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
> 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 email@example.com
> 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
> Haskell-Cafe mailing list