t      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      Safe-Infered  Safe-Infered Vector is a part of a buffer. This simulates a 2 data StrictList a = Elem !a (StrictList a) | End  #by an array and some unsafe hacks. Cf. StreamFusion Data.Stream "Wrapper of mallocForeignPtrArray.   unfoldrNTerm 20 (n -> Just (n, succ n)) a IThis is expensive and should not be used to construct lists iteratively! A recursion-enabling   would be consN 'that allocates a buffer of given size, Kinitializes the leading cell and sets the buffer pointer to the next cell.   evaluate next value in a buffer  +evaluate all values up to a given position  O(n) Converts a 'Vector a' to a '[a]'.  OFor the sake of laziness it may allocate considerably more memory than needed, if it filters out very much. &    !"#$ %&'( )%    !"#$ %&'(     !"#$ %&'( ) Safe-InferedHA space-efficient representation of a vector, supporting many efficient  operations. 1Instances of Eq, Ord, Read, Show, Data, Typeable  A variety of * for non-empty Vectors.  omits the G check for the empty case, so there is an obligation on the programmer 2 to provide a proof that the Vector is non-empty.  A variety of + for non-empty Vectors.  omits the # check for the empty case. As with , the programmer must 8 provide a separate proof that the Vector is non-empty.  A variety of , for non-empty Vectors.  omits the G check for the empty case, so there is an obligation on the programmer 2 to provide a proof that the Vector is non-empty.  A variety of - for non-empty Vectors.  omits the # check for the empty case. As with , the programmer must 8 provide a separate proof that the Vector is non-empty. Unsafe : index (subscript) operator, starting from 0, returning a G single element. This omits the bounds check, which means there is an O accompanying obligation on the programmer to ensure the bounds are checked in  some other way.  A variety of . which omits the checks on n so there is an 6 obligation on the programmer to provide a proof that 0 <= n <= / xs.  A variety of 0 which omits the checks on n so there is an 6 obligation on the programmer to provide a proof that 0 <= n <= / xs. O(1)" Build a Vector from a ForeignPtr O(1)( Deconstruct a ForeignPtr from a Vector "Run an action that is initialized 1 with a pointer to the first element to be used. 4A way of creating Vectors outside the IO monad. The Int 5 argument gives the final size of the Vector. Unlike  1 the Vector is not reallocated if the final size " is less than the estimated size. "Wrapper of mallocForeignPtrArray. BGiven the maximum size needed and a function to make the contents & of a Vector, createAndTrim makes the . The generating 7 function is required to return the actual final size (<= the maximum @ size), and the resulting byte array is realloced to this size. CcreateAndTrim is the main mechanism for creating custom, efficient C Vector functions, using Haskell or C functions to fill the space. FJust like unsafePerformIO, but we inline it. Big performance gains as 0 it exposes lots of things to further inlining.  Very unsafe. In : particular, you should do no memory allocation inside an   block. On Hugs this is just unsafePerformIO.  1   1 Safe-Infered+We might have name the data type iterator.  portable, requires ffi experimentalhaskell@henning-thielemann.de Safe-Infered2"Wrapper of mallocForeignPtrArray. 324532453245 Safe-Infered[O(1) The empty  O(1) Construct a  containing a single element O(n) Convert a '[a]' into a 'Vector a'. O(n) Convert first n elements of a '[a]' into a 'Vector a'. O(n) Converts a 'Vector a' to a '[a]'. O(n) Convert a list into a  using a conversion function !O(n) Convert a ) into a list using a conversion function "O(1) Test whether a  is empty. #O(1) # returns the length of a  as an 6. $O(n) $1 is analogous to (:) for lists, but of different & complexity, as it requires a memcpy. %O(n)# Append an element to the end of a  &O(1) Extract the first element of a , which must be non-empty. 5 An exception will be thrown in the case of an empty . 'O(1)* Extract the elements after the head of a , which must be non-empty. 5 An exception will be thrown in the case of an empty . (O(1) Extract the last element of a &, which must be finite and non-empty. 5 An exception will be thrown in the case of an empty . )O(1) Return all the elements of a  except the last one. 5 An exception will be thrown in the case of an empty . *O(n) Append two Vectors +O(n) + f xs is the  obtained by applying f to each  element of xs. ,O(n) , xs% efficiently returns the elements of xs in reverse order. -O(n) The - function takes a element and a   and ` intersperses'& that element between the elements of  the 2. It is analogous to the intersperse function on  Lists. .The .1 function transposes the rows and columns of its   argument. //<, applied to a binary operator, a starting value (typically ? the left-identity of the operator), and a Vector, reduces the  0 using the binary operator, from left to right. + This function is subject to array fusion. 0 'foldl\'' is like /!, but strict in the accumulator. 111, applied to a binary operator, a starting value 7 (typically the right-identity of the operator), and a ,  reduces the 0 using the binary operator, from right to left.  However, it is not the same as /! applied to the reversed vector.  Actually 1+ starts processing with the first element, D and thus can be used for efficiently building a singly linked list  by  foldr (:) [] vec.  Unfortunately 1$ is quite slow for low-level loops, 2 since GHC (up to 6.12.1) cannot detect the loop. 22 is a variant of / that has no starting value 1 argument, and thus must be applied to non-empty s. + This function is subject to array fusion. 5 An exception will be thrown in the case of an empty . 3 'foldl1\'' is like 2!, but strict in the accumulator. 5 An exception will be thrown in the case of an empty . 44 is a variant of 1& that has no starting value argument, ' and thus must be applied to non-empty s 5 An exception will be thrown in the case of an empty . 5O(n) Concatenate a list of s. 6Map a function over a  and concatenate the results 7 This is like mconcat . map f, ! but in many cases the result of f will not be storable. 8O(n) Applied to a predicate and a , 8 determines if  any element of the  satisfies the predicate. 9O(n) Applied to a predicate and a , 9 determines  if all elements of the  satisfy the predicate. :O(n) :" returns the maximum value from a   This function will fuse. 5 An exception will be thrown in the case of an empty . ;O(n) ;" returns the minimum value from a   This function will fuse. 5 An exception will be thrown in the case of an empty . @The @( function behaves like a combination of + and  /-; it applies a function to each element of a , G passing an accumulating parameter from left to right, and returning a = final value of this accumulator together with the new list. AThe A( function behaves like a combination of + and  1-; it applies a function to each element of a , G passing an accumulating parameter from right to left, and returning a 7 final value of this accumulator together with the new . BO(n)9 map functions, provided with the index at each position CC is similar to /#, but returns a list of successive 8 reduced values from the left. This function will fuse.  B scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]  Note that & last (scanl f z xs) == foldl f z xs. DD is a variant of C& that has no starting value argument.  This function will fuse. 0 scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...] E*scanr is the right-to-left dual of scanl. FF is a variant of E& that has no starting value argument. GO(n) G n x is a  of length n with x  the value of every element. HO(n) H n f x is a  of length n  where the elements of x* are generated by repeated application of f. IO(n), where n# is the length of the result. The I # function is analogous to the List 'unfoldr'. I builds a  8 from a seed value. The function takes the element and  returns 7 if it is done producing the 'Vector or returns  8 (a,b), in which case, a is the next element in the ,  and b+ is the seed value for further production.  Examples: B unfoldr (\x -> if x <= 5 then Just (x, x + 1) else Nothing) 0  == pack [0, 1, 2, 3, 4, 5] JO(n) Like I, J builds a  from a seed C value. However, the length of the result is limited by the first  argument to J(. This function is more efficient than I 1 when the maximum length of the result is known. The following equation relates J and I: . fst (unfoldrN n f s) == take n (unfoldr f s) KO(n) Like J this function builds a  & from a seed value with limited size. = Additionally it returns a value, that depends on the state, * but is not necessarily the state itself. 5 If end of vector and end of the generator coincide, = then the result is as if only the end of vector is reached.  Example:  W unfoldrResultN 30 Char.ord (\c -> if c>'z' then Left 1000 else Right (c, succ c)) 'a' The following equation relates J and K:   unfoldrN n f s ==  unfoldrResultN n Just * (maybe (Left Nothing) Right . f) s It is not possible to express K in terms of J. LO(n), where n is the length of the result. < This function constructs a vector by evaluating a function $ that depends on the element index.  It is a special case of J' and can in principle be parallelized.  Examples: % sample 26 (\x -> chr(ord 'a'+x)) & == pack "abcdefghijklmnopqrstuvwxyz" MO(1) M n, applied to a  xs, returns the prefix  of xs of length n, or xs itself if n > # xs. NO(1) N n xs returns the suffix of xs after the first n  elements, or  if n > # xs. OO(1) O n xs is equivalent to (M n xs, N n xs). PP, applied to a predicate p and a  xs, 0 returns the longest prefix (possibly empty) of xs of elements that  satisfy p. QQ p xs$ returns the suffix remaining after P p xs. RR p is equivalent to T (9 . p). SS behaves like R but from the end of the  breakEnd p == spanEnd (not.p) TT p xs breaks the  into two segments. It is  equivalent to (P p xs, Q p xs) UU behaves like T but from the end of the .  We have  / spanEnd (not.isSpace) "x y z" == ("x y ","z") and  spanEnd (not . isSpace) ps  == G let (x,y) = span (not.isSpace) (reverse ps) in (reverse y, reverse x) VO(n) Splits a  into components delimited by G separators, where the predicate returns True for a separator element. G The resulting components do not contain the separators. Two adjacent = separators result in an empty component in the output. eg. 4 splitWith (=='a') "aabbaca" == ["","","bb","c",""] # splitWith (=='a') [] == [] WO(n) Break a  into pieces separated by the ) argument, consuming the delimiter. I.e.  . split '\n' "a\nb\nd\ne" == ["a","b","d","e"] - split 'a' "aXaXaXa" == ["","X","X","X"] $ split 'x' "x" == ["",""] and   join [c] . split c == id  split == splitWith . (==) CAs for all splitting functions in this library, this function does 1 not copy the substrings, it just constructs new s that  are slices of the original. XLike V3, except that sequences of adjacent separators are $ treated as a single separator. eg. ( tokens (=='a') "aabbaca" == ["bb","c"] YThe Y function takes a  and returns a list of  <s such that the concatenation of the result is equal to the E argument. Moreover, each sublist in the result contains only equal  elements. For example,  < group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"] It is a special case of Z!, which allows the programmer to = supply their own equality test. It is about 40% faster than   groupBy (==) ZThe Z+ function is the non-overloaded version of Y. [O(n) The [ function takes a  and a list of  :s and concatenates the list after interspersing the first , argument between each element of the list. \O(1) . index (subscript) operator, starting from 0. ]O(n) The ]) function returns the index of the first  element in the given  which is equal to the query  element, or 7 if there is no such element. ^O(n) The ^( function returns the last index of the  element in the given  which is equal to the query  element, or 7, if there is no such element. The following  holds:  elemIndexEnd c xs == 5 (-) (length xs - 1) `fmap` elemIndex c (reverse xs) _O(n) The _ function extends ], by returning M the indices of all elements equal to the query element, in ascending order. `>count returns the number of times its argument appears in the    count = length . elemIndices ABut more efficiently than using length on the intermediate list. aThe a" function takes a predicate and a  and / returns the index of the first element in the   satisfying the predicate. bThe b function extends a, by returning the G indices of all elements satisfying the predicate, in ascending order. cc4 is a variant of findIndex, that returns the length < of the string if no element is found, rather than Nothing. dO(n) d is the  membership predicate. eO(n) e is the inverse of d fO(n) f, applied to a predicate and a ,  returns a , containing those elements that satisfy the 6 predicate. This function is subject to array fusion. gO(n) The g" function takes a predicate and a , = and returns the first element in matching the predicate, or 7  if there is no such element. H find f p = case findIndex f p of Just n -> Just (p ! n) ; _ -> Nothing hO(n) The h function takes two  and returns : * iff the first is a prefix of the second. iO(n) The i function takes two s and returns : * iff the first is a suffix of the second. The following holds: 4 isSuffixOf x y == reverse x `isPrefixOf` reverse y jO(n) j takes two s and returns a list of / corresponding pairs of elements. If one input  is short,  excess elements of the longer  are discarded. This is  equivalent to a pair of  operations. kk generalises j' by zipping with the function given as B the first argument, instead of a tupling function. For example,  k (+) is applied to two s to produce the list of  corresponding sums. lLike k but for three input vectors mLike k but for four input vectors & If you need even more input vectors, @ you might write a function yourselve using unfoldrN and viewL. nO(n) n7 transforms a list of pairs of elements into a pair of  s. Note that this performs two  operations. oO(ln)/ o selects every n th element. pO(n) = Returns n sieved vectors with successive starting elements.  deinterleave 3 (pack ['a'..'k'] ) = [pack adgj, pack behk, pack cfi]  This is the same as  . qO(n) % Almost the inverse of deinterleave. > Restriction is that all input vector must have equal length.  interleave [pack adgj, pack behk, pack cfil] = pack ['a'..'l'] rO(n)* Return all initial segments of the given , shortest first. sO(n)( Return all final segments of the given , longest first. tO(n) Make a copy of the  with its own storage. ? This is mainly useful to allow the rest of the data pointed  to by the & to be garbage collected, for example C if a large string has been read in, and only a small part of it ) is needed in the rest of the program. u Outputs a  to the specified ;. vRead a  directly from the specified ;. This ? is far more efficient than reading the characters into a list  and then using . w$Read an entire file strictly into a . This is far more . efficient than reading the characters into a < and then using  ;. It also may be more efficient than opening the file and - reading it using hGet. Files are read using ' binary mode' on Windows. xWrite a  to a file. y Append a  to a file. a !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy=>` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy` !$%*&(')"#>?<=+,-./0231456789:;CDEF@ABGHIJKLMNOPQTURSYZrsWVX[hidegf\]_^ab`cjklmntopqvuwxya !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy=> Safe-Inferedz?@ABC{|z?@ABC{|z?@ABC{| Safe-Infered  Example: { *Data.StorableVector.Lazy> unfoldrResult (ChunkSize 5) (\c -> if c>'z' then Left (Char.ord c) else Right (c, succ c)) 'a'  (VectorLazy.fromChunks [Vector.pack "abcde",Vector.pack "fghij",Vector.pack "klmno",Vector.pack "pqrst",Vector.pack "uvwxy",Vector.pack "z"],123) extendL size x y prepends the chunk x' and merges it with the first chunk of y if the total size is at most size. &This way you can prepend small chunks 6while asserting a reasonable average size for chunks. dropMarginRem n m xs drops at most the first m elements of xs and ensures that xs still contains n elements. FAdditionally returns the number of elements that could not be dropped due to the margin constraint. That is dropMarginRem n m xs == (k,ys) implies length xs - m == length ys - k.  Requires length xs >= n. Generates laziness breaks 8wherever one of the input signals has a chunk boundary. .Preserves chunk pattern of the last argument. .Preserves chunk pattern of the last argument. .Preserves chunk pattern of the last argument. Interleave lazy vectors 9while maintaining the chunk pattern of the first vector. -All input vectors must have the same length. =Ensure a minimal length of the list by appending pad values. #Read the rest of a file lazily and .provide the reason of termination as IOError. If IOError is EOF (check with System.Error.isEOFError err), %then the file was read successfully. IOnly access the final IOError after you have consumed the file contents, Isince finding out the terminating reason forces to read the entire file. -Make also sure you read the file completely, 7because it is only closed when the file end is reached "(or an exception is encountered). TODO: -In ByteString.Lazy the chunk size is reduced &if data is not immediately available. %Maybe we should adapt that behaviour 'but when working with realtime streams .that may mean that the chunks are very small. 8The file can only closed after all values are consumed. LThat is you must always assert that you consume all elements of the stream, 6and that no values are missed due to lazy evaluation. CThis requirement makes this function useless in many applications. Z}~DEFGHIJKR}~R}~W}~DEFGHIJK Safe-Inferedz{|z{|portable, requires ffi experimentalhaskell@henning-thielemann.de Safe-Infered f Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3) g VS.unpack $ runSTVector (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; return arr) s VS.unpack $ runSTVector (do arr <- new 10 'a'; Monad.mapM_ (\n -> modify arr (mod n 8) succ) [0..10]; return arr) Returns Just e, when the element e could be read and 7 if the index was out of range. .This way you can avoid duplicate index checks that may be needed when using .  f Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3)  In future  will replace . Returns :! if the element could be written and L if the index was out of range.   runSTVector (do arr <- new_ 10; foldr (\c go i -> maybeWrite arr i c >>= \cont -> if cont then go (succ i) else return arr) (error "unreachable") ['a'..] 0)  In future  will replace .  Similar to .  In future  will replace .  This is like " but it does not copy the vector. <You must make sure that you never write again to the array. It is best to use  only at the end of a block, that is run by M.  :module + Data.STRef  VS.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapST (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VS.pack [1,2,3,4::Data.Int.Int16]))   *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [1,2,3,4::Data.Int.Int16]))  "abcd" 3The following should not work on infinite streams, since we are in N with strict O. But it works. Why?  *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [0::Data.Int.Int16 ..]))  "Interrupted.  Safe-Infered O toLazyStorableVector (ChunkSize 7) $ Data.Monoid.mconcat $ map put ['a'..'z'] Set a laziness break. PP Safe-InferedGenerates laziness breaks Kwherever either the lazy length number or the vector has a chunk boundary. 0Preserves the chunk pattern of the lazy vector. 5}5} portable, requires ffi experimentalhaskell@henning-thielemann.de Safe-Infered f Control.Monad.ST.runST (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; read arr 3) g VS.unpack $ runSTVector (do arr <- new_ 10; Monad.zipWithM_ (write arr) [9,8..0] ['a'..]; return arr)   :module + Data.STRef  VS.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapST (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VS.pack [1,2,3,4::Data.Int.Int16]))   *Data.StorableVector.ST.Strict Data.STRef> VL.unpack $ Control.Monad.ST.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [1,2,3,4::Data.Int.Int16]))  "abcd" 3The following should not work on infinite streams, since we are in Q with strict O. But it works. Why?  *Data.StorableVector.ST.Strict Data.STRef.Lazy> VL.unpack $ Control.Monad.ST.Lazy.runST (do ref <- newSTRef 'a'; mapSTLazy (\ _n -> do c <- readSTRef ref; modifySTRef ref succ; return c) (VL.pack VL.defaultChunkSize [0::Data.Int.Int16 ..]))  "Interrupted.  Safe-InferedRSTUVWXRSTUVWXRSTUVWXY !"##$%&'() *+,-./012'3456789:;<=>?@ABCDEFGHI)J(KLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~#()*+,./0UXS12h'8C9:=>?EFGHI(K)JOLMYZ[]\`rwxy{|'2,/VTS2YZ[    ' . r     V , w ) ( ? 1 Z Y 4567Y2Z    #%*'##h'()storablevector-0.2.8Data.StorableVector.BaseData.StorableVector.PointerData.StorableVector.ST.StrictData.StorableVector Data.StorableVector.Lazy.PointerData.StorableVector.Lazy Data.StorableVector.Lazy.Builder Data.StorableVector.Lazy.PatternData.StorableVector.ST.LazyData.StorableVector.MemoryData.StorableVector.CursorData.StorableVector.ST.Private Data.List.HTsliceHorizontal'Data.StorableVector.Lazy.PointerPrivate,Data.StorableVector.Lazy.PointerPrivateIndexVectorSV unsafeHead unsafeTail unsafeLast unsafeInit unsafeIndex unsafeTake unsafeDropfromForeignPtr toForeignPtr withStartPtrincPtr unsafeCreatecreate createAndTrimcreateAndTrim'inlinePerformIOPointerfptrptrleftconsviewLswitchLempty singletonpackpackNunpackpackWith unpackWithnulllengthsnocheadtaillastinitappendmapreverse intersperse transposefoldlfoldl'foldrfoldl1foldl1'foldr1concat concatMapmonoidConcatMapanyallmaximumminimumswitchRviewR mapAccumL mapAccumR mapIndexedscanlscanl1scanrscanr1 replicateiterateNunfoldrunfoldrNunfoldrResultNsampletakedropsplitAt takeWhile dropWhilebreakbreakEndspanspanEnd splitWithsplittokensgroupgroupByjoinindex elemIndex elemIndexEnd elemIndicescount findIndex findIndicesfindIndexOrEndelemnotElemfilterfind isPrefixOf isSuffixOfzipzipWithzipWith3zipWith4unzipsieve deinterleave interleaveinitstailscopyhPuthGetreadFile writeFile appendFile ChunkSizechunks chunkSizedefaultChunkSize fromChunks unfoldrResultsampleNiteraterepeatcycleequalextendLpointer crochetLChunkcrochetL dropMarginRem dropMarginzipWithLastPatternzipWithLastPattern3zipWithLastPattern4 zipWithSize zipWithSize3 zipWithSize4interleaveFirstPatternpadpadAltcancelNullVector fromChunkhGetContentsAsynchGetContentsSync readFileAsync moduleErrornewnew_readwritemodify maybeRead maybeWrite maybeModify unsafeRead unsafeWrite unsafeModifyfreeze unsafeFreezethaw runSTVectormapST mapSTLazyBuildertoLazyStorableVectorputflushLazySizetakeVectorPatternsplitAtVectorPatternmallocForeignPtrArrayBuffer GeneratorcreateIO unfoldrNTerm advanceIO evaluateToIObufferstartmaxLenmemorysizegencursorunfoldrNTermIO unfoldrNIOzipNWithwhileM obviousNullIOviewLIOdropIO $fShowVectorbaseGHC.ListunsafeToVectorghc-prim GHC.TypesInt Data.MaybeNothingJust GHC.ClassesnotTrueGHC.IO.Handle.TypesHandleGHC.BaseString$fMonoidVector $fEqVector $fCChunkSize$fMonoidChunkSize$fNumChunkSize$fArbitraryChunkSize$fArbitraryVectorFalseGHC.STrunSTST>>=$fMonoidBuilderControl.Monad.ST.Lazy.Imp