packages feed

type-iso 1.0.0.0 → 1.0.1.0

raw patch · 3 files changed

+30/−4 lines, 3 filesdep +containersdep +vectordep +vector-builderPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: containers, vector, vector-builder

API changes (from Hackage documentation)

- Data.Types.Injective: instance Data.Default.Class.Default a => Data.Types.Injective.Injective (GHC.Base.Maybe b) (Data.Either.Either a b)
+ Data.Types.Injective: instance Data.Default.Class.Default a => Data.Types.Injective.Injective (GHC.Maybe.Maybe b) (Data.Either.Either a b)
+ Data.Types.Injective: instance Data.Vector.Generic.Base.Vector v a => Data.Types.Injective.Injective (Data.Sequence.Internal.Seq a) (v a)
+ Data.Types.Injective: instance Data.Vector.Generic.Base.Vector v a => Data.Types.Injective.Injective (v a) (Data.Sequence.Internal.Seq a)
+ Data.Types.Isomorphic: instance Data.Vector.Generic.Base.Vector v a => Data.Types.Isomorphic.Iso (Data.Sequence.Internal.Seq a) (v a)
+ Data.Types.Isomorphic: instance Data.Vector.Generic.Base.Vector v a => Data.Types.Isomorphic.Iso (v a) (Data.Sequence.Internal.Seq a)
- Data.Types.Isomorphic: from :: forall b a. (Iso a b) => b -> a
+ Data.Types.Isomorphic: from :: forall b a. Iso a b => b -> a

Files

Data/Types/Injective.hs view
@@ -9,13 +9,16 @@ --  for the following equivalence classes:
 --
 --  * @{Strict Text, Lazy Text, String}@. 'ByteString's are not part of this,
---    since there exists more than one way to turn unicode text into a ByteString
+--    since there is more than one way to turn unicode text into a ByteString
 --    (see "Data.Text.Encoding" and "Data.Text.Lazy.Encoding").
---  * @{Whole, Integer}@. Be advices, though, that Peano numbers may contain
+--  * @{Whole, Integer}@. Be advised, though, that Peano numbers may contain
 --    unobservable infinities (i.e. @infinity = S infinity@) and thus,
 --    the conversion to Integer may not terminate.
 --  * @{Nat, Natural}@. For finite values, they're extensionally equivalent,
 --    but 'Nat' has lazy infinity.
+--  * @{Seq a, Vector a}@. Supports all kinds of immutable vectors of elements:
+--    boxed, unboxed, primitive, storable. @[a]@ is not part of this, as
+--    typeclass 'IsList' provides 'fromList' and 'toList'.
 --
 --  Additional injections:
 --
@@ -29,10 +32,14 @@ import Data.Default
 import qualified Data.Maybe as M
 import qualified Data.Ratio as R
+import qualified Data.Sequence as S
 import qualified Data.Text as TS
 import qualified Data.Text.Encoding as TS
 import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Encoding as TL
+import qualified Data.Vector.Generic as VG
+import qualified VectorBuilder.Builder as VB
+import qualified VectorBuilder.Vector as VB
 import qualified Numeric.Peano as PN
 
 -- |The class relation between types @a@ and @b@ s.t. @a@ can be injected
@@ -91,3 +98,9 @@ instance Injective PN.Whole R.Rational where
    to (PN.Whole n PN.Pos) = (fromIntegral n) R.% 1
    to (PN.Whole n PN.Neg) = negate (fromIntegral n) R.% 1
+
+-- equivalence class of finite sequences
+instance VG.Vector v a => Injective (S.Seq a) (v a) where
+  to = VB.build . VB.foldable
+instance VG.Vector v a => Injective (v a) (S.Seq a) where
+  to v = S.fromFunction (VG.length v) (v VG.!)
Data/Types/Isomorphic.hs view
@@ -12,8 +12,10 @@ 
 import qualified Numeric.Natural as N
 import qualified Numeric.Peano as PN
+import qualified Data.Sequence as S
 import qualified Data.Text as TS
 import qualified Data.Text.Lazy as TL
+import qualified Data.Vector.Generic as VG
 
 import Data.Types.Injective
 
@@ -67,3 +69,7 @@ -- Peano wholes and integers.
 instance Iso PN.Whole Integer
 instance Iso Integer PN.Whole
+
+-- equivalence class of finite sequences
+instance (VG.Vector v a) => Iso (S.Seq a) (v a)
+instance (VG.Vector v a) => Iso (v a) (S.Seq a)
type-iso.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                type-iso
-version:             1.0.0.0
+version:             1.0.1.0
 synopsis:            Typeclasses for injective relations and isomorphisms between types.
 description:         This package defines \"can be cast to\" relations between types: two types a and b are an instance of Injective if there's an injective function from a to b. If there is also an injective function from b to a, a and b are instances of Iso, meaning that one can convert back and forth losslessly (up to some appropriate notion of equality). The main purpose of this little package is to provide easy casting between the common string types (String, strict/lazy Text) and numeric types (Integers, Peano numbers), without having to look up the names of the various conversion functions all the time.
 homepage:            https://github.com/ombocomp/type-iso
@@ -22,5 +22,12 @@ library
   exposed-modules:     Data.Types.Isomorphic, Data.Types.Injective
   other-extensions:    MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, ExplicitForAll, GADTs
-  build-depends:       base >=4.7 && <5, nats >=0.2, text >=1.1, numericpeano >= 0.2, data-default >= 0.5
+  build-depends:       base >=4.7 && <5
+                     , containers >= 0.5.6.2
+                     , nats >=0.2
+                     , text >=1.1
+                     , numericpeano >= 0.2
+                     , data-default >= 0.5
+                     , vector >= 0.5
+                     , vector-builder >= 0.3.7
   default-language:    Haskell2010