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.

---Frank

On Wednesday, Sep 3, 2003, at 04:30 US/Eastern, Wamberto Vasconcelos wrote:

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          [EMAIL PROTECTED]
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
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to