Last active
August 27, 2015 02:08
-
-
Save fumieval/873c7d0ebc7e40ace5b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Vector as V | |
import qualified Data.Vector.Generic as G | |
import qualified Data.Vector.Fusion.Bundle as Bundle | |
newtype Arr a = Arr [V.Vector a] | |
(<|) :: a -> Arr a -> Arr a | |
a <| Arr (v:w:xs) | |
| V.length v == V.length w = Arr (G.unstream (Bundle.cons a $ G.stream v Bundle.++ G.stream w) : xs) | |
a <| Arr xs = Arr (V.singleton a : xs) | |
index :: Int -> Arr a -> Maybe a | |
index i (Arr (v:vs)) | |
| i < V.length v = Just (v V.! i) | |
| otherwise = index (i - V.length v) (Arr vs) | |
index _ _ = Nothing |
jamesdbrock
commented
Aug 27, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment