[Haskell] Recursive definition of fibonacci with Data.Vector
Brian Sniffen
brian.sniffen at gmail.com
Sun Mar 7 18:32:32 EST 2010
On Sun, Mar 7, 2010 at 6:08 PM, Edgar Z. Alvarenga <edgar at ymonad.com> wrote:
> On Sun, 07/Mar/2010 at 17:04 -0500, Brian Sniffen wrote:
>> To what do you expect 'v' to refer?
>
> Data.Vector
I meant the lowercase v, as in (V.tail v).
As to strictness, that strictness is exactly how Vector gets its
performance benefit: by strictly allocating memory, it can solve
problems without allocation.
-Brian
>> Why use 'let' for the definition?
>>
>> And then once you sort it out to something like:
>>
>> fib = 0 `V.cons` (1 `V.cons` V.zipWith (+) fib (V.tail fib))
>
> Was just a typo (the line above was copy from ghci).
>
>> The three Vector operations used here are strict in the length of
>> their arguments. So what length should 'fib' have? 2 more than its
>> own length... which is more RAM than this computer has.
>
> Ok, now I understood, is because of the strictness. The next time I
> would look in the source code first.
>
> Thanks,
> Edgar
>
>> -Brian
>>
>> On Sun, Mar 7, 2010 at 3:49 PM, Edgar Z. Alvarenga <edgar at ymonad.com> wrote:
>> > 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))
>> >
>> > Cheers,
>> > Edgar
>> > _______________________________________________
>> > Haskell mailing list
>> > Haskell at haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell
>> >
>>
>>
>>
>> --
>> Brian Sniffen
>> http://evenmere.org/~bts/
>> <bts at evenmere.org>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
--
Brian Sniffen
http://evenmere.org/~bts/
<bts at evenmere.org>
More information about the Haskell
mailing list