vector-binary (empty) → 0.1.0
raw patch · 4 files changed
+135/−0 lines, 4 filesdep +basedep +binarydep +vectorsetup-changed
Dependencies added: base, binary, vector
Files
- Data/Vector/Binary.hs +70/−0
- LICENSE +30/−0
- Setup.lhs +4/−0
- vector-binary.cabal +31/−0
+ Data/Vector/Binary.hs view
@@ -0,0 +1,70 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Data.Vector.Binary () where++import Data.Binary+import System.IO.Unsafe+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Generic.Mutable as M++import qualified Data.Vector as V+import qualified Data.Vector.Unboxed as U++-- Both binary instances below originate from the vector-binary-instances+-- library. To avoid the overlapping instances problem the instances+-- are restricted to monomorphic vector types.++instance (U.Unbox e, Binary e) => Binary (U.Vector e) where+ put v = do+ put (G.length v)+ mapM_ put (G.toList v)++ -- this is morally sound, if very awkward.+ -- all effects are contained, and can't escape the unsafeFreeze+ {-# INLINE get #-}+ get = do+ n <- get++ -- new unitinialized array+ mv <- lift $ M.new n++ let fill i+ | i < n = do+ x <- get+ (unsafePerformIO $ M.unsafeWrite mv i x) `seq` return ()+ fill (i+1)++ | otherwise = return ()++ fill 0++ lift $ G.unsafeFreeze mv++instance Binary e => Binary (V.Vector e) where+ put v = do+ put (G.length v)+ mapM_ put (G.toList v)++ -- this is morally sound, if very awkward.+ -- all effects are contained, and can't escape the unsafeFreeze+ {-# INLINE get #-}+ get = do+ n <- get++ -- new unitinialized array+ mv <- lift $ M.new n++ let fill i+ | i < n = do+ x <- get+ (unsafePerformIO $ M.unsafeWrite mv i x) `seq` return ()+ fill (i+1)++ | otherwise = return ()++ fill 0++ lift $ G.unsafeFreeze mv++lift :: IO b -> Get b+lift = return .unsafePerformIO
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Don Stewart 2010, Jakub Waszczuk 2012++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Don Stewart nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ vector-binary.cabal view
@@ -0,0 +1,31 @@+name: vector-binary+version: 0.1.0+synopsis: Binary instances for vector types+description: + The library provides binary instances for boxed and unboxed vector types.+ The code is based on the vector-binary-instances package but restricts+ instances to monomorphic vector types.+license: BSD3+license-file: LICENSE+cabal-version: >= 1.6+author: Jakub Waszczuk+maintainer: waszczuk.kuba@gmail.com+stability: provisional+category: Data+homepage: https://github.com/kawu/vector-binary+build-type: Simple++library+ build-depends:+ base >= 4 && < 5+ , vector+ , binary++ exposed-modules:+ Data.Vector.Binary++ ghc-options: -Wall++source-repository head+ type: git+ location: git://github.com/kawu/vector-binary.git