Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.33 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Haskell: Datastruture with O(1) append and O(1) indexing?
  2. import Data.Array
  3. fibs = listArray (0, n-1) $ 0 : 1 : [fibs!(i-1) + fibs!(i-2) | i <- [2..n-1]]
  4.   where n = 100
  5.        
  6. import Data.Vector.Unboxed as V
  7. fibs = constructN 100 f
  8.   where f xs | i < 2 = i
  9.              | otherwise = xs!(i-1) + xs!(i-2)
  10.              where i = V.length xs