fixed-vector / fixed-vector-binary / Data / Vector / Fixed / Instances / Binary.hs

{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Module with binary instances for data types defined in fixed
--   vector
module Data.Vector.Fixed.Instances.Binary where

import           Data.Vector.Fixed             (Arity)
import qualified Data.Vector.Fixed           as F
import qualified Data.Vector.Fixed.Boxed     as B
import qualified Data.Vector.Fixed.Unboxed   as U
import qualified Data.Vector.Fixed.Primitive as P
import qualified Data.Vector.Fixed.Storable  as S
import           Data.Binary                   (Binary(..))


instance (Arity n, Binary a) => Binary (B.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, P.Prim a, Binary a) => Binary (P.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, S.Storable a, Binary a) => Binary (S.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (U.Unbox n a, Binary a) => Binary (U.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, Binary a) => Binary (F.VecList n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Binary a) => Binary (F.Only a) where
  put (F.Only a) = put a
  get = F.Only `fmap` get

instance Binary (F.Empty a) where
  put _ = return ()
  get = return F.Empty
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.