sext 0.1.1 → 0.1.2
raw patch · 5 files changed
+93/−18 lines, 5 filesdep +sextdep +vectordep ~basedep ~bytestringdep ~template-haskellPVP ok
version bump matches the API change (PVP)
Dependencies added: sext, vector
Dependency ranges changed: base, bytestring, template-haskell, text
API changes (from Hackage documentation)
+ Data.Sext.Class: instance Data.Sext.Class.Sextable (Data.Vector.Vector a)
+ Data.Sext.Class: instance GHC.Classes.Eq (Data.Sext.Class.Sext i Data.ByteString.Internal.ByteString)
+ Data.Sext.Class: instance GHC.Classes.Eq (Data.Sext.Class.Sext i Data.Text.Internal.Text)
+ Data.Sext.Class: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Sext.Class.Sext i (Data.Vector.Vector a))
+ Data.Sext.Class: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Sext.Class.Sext i [a])
+ Data.Sext.Class: instance GHC.Classes.Ord (Data.Sext.Class.Sext i Data.ByteString.Internal.ByteString)
+ Data.Sext.Class: instance GHC.Classes.Ord (Data.Sext.Class.Sext i Data.Text.Internal.Text)
+ Data.Sext.Class: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Sext.Class.Sext i (Data.Vector.Vector a))
+ Data.Sext.Class: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Sext.Class.Sext i [a])
Files
- sext.cabal +29/−11
- src/Data/Sext.hs +8/−2
- src/Data/Sext/Class.hs +28/−1
- src/Data/Sext/TH.hs +4/−4
- tests/Main.hs +24/−0
sext.cabal view
@@ -1,22 +1,21 @@ name: sext-version: 0.1.1+version: 0.1.2 cabal-version: >=1.10 build-type: Simple license: BSD3 license-file: LICENSE maintainer: dima@dzhus.org-stability: Experimental-homepage: http://github.com/dzhus/sext/-synopsis: Lists, Texts and ByteStrings with type-encoded length+homepage: https://github.com/dzhus/sext#readme+bug-reports: https://github.com/dzhus/sext/issues+synopsis: Lists, Texts, ByteStrings, and Vectors with type-encoded length description: Sext (/s/tatic t/ext/) provides type-level safety for basic operations on string-like types (finite lists of elements). Use it when you need static guarantee on lengths of strings produced in your code. category: Data, Text, Type System author: Dmitry Dzhus-tested-with: GHC ==7.10.3 GHC ==8.0.1 source-repository head type: git- location: http://github.com/dzhus/sext+ location: https://github.com/dzhus/sext flag bytestring description:@@ -26,27 +25,46 @@ description: Build interface for Text +flag vector+ description:+ Build interface for Vector+ library if flag(bytestring) build-depends:- bytestring ==0.10.*+ bytestring <0.11 cpp-options: -DWITH_BS if flag(text) build-depends:- text >=1.1 && <1.3+ text <1.3 cpp-options: -DWITH_TEXT+ + if flag(vector)+ build-depends:+ vector <0.12+ cpp-options: -DWITH_VECTOR exposed-modules: Data.Sext Data.Sext.Class Data.Sext.TH build-depends:- base >=4.7 && <5,- template-haskell >=2.9 && <2.12+ base <5,+ template-haskell <2.12 default-language: Haskell2010 hs-source-dirs: src other-modules: Paths_sext- ghc-options: -Wall+ ghc-options: -Wall -Wall +test-suite sext-example+ type: exitcode-stdio-1.0+ main-is: Main.hs+ build-depends:+ base <5,+ template-haskell <2.12,+ sext <0.2+ default-language: Haskell2010+ hs-source-dirs: tests+ ghc-options: -Wall
src/Data/Sext.hs view
@@ -20,6 +20,12 @@ An example application would be a network exchange protocol built of packets with fixed-width fields: +> {-# LANGUAGE DataKinds #-}+> {-# LANGUAGE OverloadedStrings #-}+> {-# LANGUAGE TemplateHaskell #-}+>+> import Data.Sext+> > mkPacket :: String -> Sext 32 String > mkPacket inp = > -- 5-character version signature@@ -32,7 +38,7 @@ > payload = createLeft ' ' inp > checksum :: Sext 2 String > checksum = createLeft ' ' $-> show $ length payload `mod` 100+> show $ Data.Sext.length payload `mod` 100 > > message :: Sext 64 String > message = mkPacket "Hello" `append` mkPacket "world"@@ -69,7 +75,7 @@ -- * Sextable class , Sext- , Sextable(C.unsafeCreate, C.unwrap)+ , Sextable(unsafeCreate, unwrap) ) where
src/Data/Sext/Class.hs view
@@ -26,6 +26,10 @@ import qualified Data.Text as T #endif +#ifdef WITH_VECTOR+import qualified Data.Vector as V+#endif+ #if MIN_VERSION_base(4,9,0) import GHC.TypeLits hiding (Text) #else@@ -71,13 +75,15 @@ instance (Show a, Sextable a) => Show (Sext i a) where- show s = show $ unwrap s+ show = show . unwrap+ showsPrec p = showsPrec p . unwrap instance Sextable [a] where type Elem [a] = a data Sext i [a] = List [a]+ deriving (Eq, Ord) unsafeCreate = List unwrap (List l) = l@@ -95,6 +101,7 @@ type Elem T.Text = Char data Sext i T.Text = Text T.Text+ deriving (Eq, Ord) unsafeCreate = Text unwrap (Text t) = t@@ -113,6 +120,7 @@ type Elem B.ByteString = Word8 data Sext i B.ByteString = ByteString B.ByteString+ deriving (Eq, Ord) unsafeCreate = ByteString unwrap (ByteString t) = t@@ -123,4 +131,23 @@ map = B.map take = B.take drop = B.drop+#endif+++#ifdef WITH_VECTOR+instance Sextable (V.Vector a) where+ type Elem (V.Vector a) = a++ data Sext i (V.Vector a) = Vector (V.Vector a)+ deriving (Eq, Ord)++ unsafeCreate = Vector+ unwrap (Vector t) = t++ length = V.length+ append = (V.++)+ replicate = V.replicate+ map = V.map+ take = V.take+ drop = V.drop #endif
src/Data/Sext/TH.hs view
@@ -53,8 +53,8 @@ [ ClassP ''IsString [VarT at] , ClassP ''Sextable [VarT at]] $ #endif+ AppT (AppT- (AppT- (ConT ''Sext)- (LitT $ NumTyLit (fromIntegral $ P.length s)))- (VarT at)))+ (ConT ''Sext)+ (LitT $ NumTyLit (fromIntegral $ P.length s)))+ (VarT at))
+ tests/Main.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}++import Data.Sext++mkPacket :: String -> Sext 32 String+mkPacket inp =+ -- 5-character version signature+ $(sext "PKT10") `append`+ -- 25-character payload+ payload `append`+ -- 2-character payload checksum+ checksum+ where+ payload = createLeft ' ' inp+ checksum :: Sext 2 String+ checksum = createLeft ' ' $+ show $ Data.Sext.length payload `mod` 100++message :: Sext 64 String+message = mkPacket "Hello" `append` mkPacket "world"++main = print message