3 ms·
> I know this is a big claim Perhaps, but it needn't be to get the same asymptotic performance. Okasaki's simplest random access list has performance proofs t
by jbapple 16y ago
> I know this is a big claim
Perhaps, but it needn't be to get the same asymptotic performance.
Okasaki's simplest random access list has performance proofs that depend only on the simplest properties of binary numbers, rather than those of the Exponential-Golumb coding, and the code is very easy to write:
data BRAL a = Empty
| Full (Maybe a) (BRAL (a,a))
deriving (Show)
cons :: a -> BRAL a -> BRAL a
cons x Empty = Full (Just x) Empty
cons x (Full Nothing ys) = Full (Just x) ys
cons x (Full (Just y) ys) = Full Nothing (cons (x,y) ys)
nth :: Integer -> BRAL a -> a
nth 0 (Full (Just x) _) = x
nth 0 (Full Nothing xs) = fst (nth 0 xs)
nth n (Full (Just _) xs) = nth (n-1) (Full Nothing xs)
nth n (Full Nothing xs) =
let pair = nth (n`div`2) xs
in if n`mod`2 == 0
then fst pair
else snd pair