[Haskell-cafe] Re: [Haskell] Recursive definition of fibonacci with
Data.Vector
Don Stewart
dons at galois.com
Sun Mar 7 15:56:40 EST 2010
edgar:
> Hello,
>
> why I can't define a recursive vector using Data.Vector, like in
> the example:
>
> import qualified Data.Vector as V
>
> let fib = 0 `V.cons` (1 `V.cons` V.zipWith (+) fib (V.tail v))
>
There's a typo:
fib = 0 `V.cons` (1 `V.cons` V.zipWith (+) fib (V.tail fib))
Which let's it typecheck.
But I don't think this is a sensible use of vectors.
In fact, infinite vectors make no sense, as far as I can tell -- these
are fundamentally bounded structures. GHC even optimizes it to:
fib = fib
(literally!).
$ time ./A
A: <<loop>>
-- Don
More information about the Haskell-Cafe
mailing list