packages feed

comfort-array 0.5 → 0.5.1

raw patch · 3 files changed

+48/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Array.Comfort.Container: class (C f) => Indexed f where {
+ Data.Array.Comfort.Container: indices :: Indexed f => Shape f -> [Index f]
+ Data.Array.Comfort.Container: instance Data.Array.Comfort.Container.C f => Data.Array.Comfort.Container.Indexed (Data.NonEmptyPrivate.T f)
+ Data.Array.Comfort.Container: instance Data.Array.Comfort.Container.Indexed []
+ Data.Array.Comfort.Container: instance Data.Array.Comfort.Container.Indexed f => Data.Array.Comfort.Shape.Indexed (Data.Array.Comfort.Container.Shape f)
+ Data.Array.Comfort.Container: instance GHC.Classes.Ord k => Data.Array.Comfort.Container.Indexed (Data.Map.Internal.Map k)
+ Data.Array.Comfort.Container: instance GHC.Classes.Ord k => Data.Array.Comfort.Container.Indexed (Data.NonEmpty.Map.T k)
+ Data.Array.Comfort.Container: type family Index f;
+ Data.Array.Comfort.Container: unifiedSizeOffset :: (Indexed f, Checking check) => Shape f -> (Int, Index f -> Result check Int)

Files

comfort-array.cabal view
@@ -1,5 +1,5 @@ Name:             comfort-array-Version:          0.5+Version:          0.5.1 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -90,7 +90,7 @@   test-module.list  Source-Repository this-  Tag:         0.5+  Tag:         0.5.1   Type:        darcs   Location:    https://hub.darcs.net/thielema/comfort-array/ 
src/Data/Array/Comfort/Container.hs view
@@ -5,7 +5,7 @@ while preserving the container structure. -} module Data.Array.Comfort.Container (-   C(..), EqShape(..), NFShape(..),+   C(..), EqShape(..), NFShape(..), Indexed(..),    ) where  import qualified Data.Array.Comfort.Shape as Shape@@ -40,7 +40,14 @@ class (C f) => EqShape f where    eqShape :: Shape f -> Shape f -> Bool +class (C f) => Indexed f where+   type Index f+   indices :: Shape f -> [Index f]+   unifiedSizeOffset ::+      (Shape.Checking check) =>+      Shape f -> (Int, Index f -> Shape.Result check Int) + instance (NFShape f) => NFData (Shape f) where    rnf = rnfShape @@ -50,7 +57,12 @@ instance (C f) => Shape.C (Shape f) where    size = shapeSize +instance (Indexed f) => Shape.Indexed (Shape f) where+   type Index (Shape f) = Index f+   indices = indices+   unifiedSizeOffset = unifiedSizeOffset + instance C [] where    data Shape [] = ShapeList Int       deriving (Show)@@ -64,7 +76,16 @@ instance NFShape [] where    rnfShape (ShapeList n) = rnf n +instance Indexed [] where+   type Index [] = Int+   indices (ShapeList len) = take len $ iterate (1+) 0+   unifiedSizeOffset (ShapeList len) =+      (len, \ix -> do+         Shape.assert "Shape.Container.[]: array index too small" $ ix>=0+         Shape.assert "Shape.Container.[]: array index too big" $ ix<len+         return ix) + {- instance Foldable only available since GHC-8.0. :-( Could be circumvented by Data.Orphans@@ -102,7 +123,17 @@ instance (NFShape f) => NFShape (NonEmpty.T f) where    rnfShape (ShapeNonEmpty c) = rnfShape c +instance (C f) => Indexed (NonEmpty.T f) where+   type Index (NonEmpty.T f) = Int+   indices shape = take (shapeSize shape) $ iterate (1+) 0+   unifiedSizeOffset shape =+      let len = shapeSize shape in+      (len, \ix -> do+         Shape.assert "Shape.Container.NonEmpty: array index too small" $ ix>=0+         Shape.assert "Shape.Container.NonEmpty: array index too big" $ ix<len+         return ix) + instance C Empty.T where    data Shape Empty.T = ShapeEmpty       deriving (Show)@@ -133,7 +164,12 @@ instance (NFData k, Ord k) => NFShape (Map k) where    rnfShape (ShapeMap set) = rnf set +instance (Ord k) => Indexed (Map k) where+   type Index (Map k) = k+   indices (ShapeMap set) = Set.toAscList set+   unifiedSizeOffset (ShapeMap set) = Shape.unifiedSizeOffset set + instance (Ord k) => C (NonEmptyMap.T k) where    data Shape (NonEmptyMap.T k) = ShapeNonEmptyMap (NonEmptySet.T k)       deriving (Show)@@ -148,3 +184,10 @@  instance (NFData k, Ord k) => NFShape (NonEmptyMap.T k) where    rnfShape (ShapeNonEmptyMap set) = rnf set++instance (Ord k) => Indexed (NonEmptyMap.T k) where+   type Index (NonEmptyMap.T k) = k+   indices (ShapeNonEmptyMap set) =+      NonEmpty.flatten $ NonEmptySet.toAscList set+   unifiedSizeOffset (ShapeNonEmptyMap set) =+      Shape.unifiedSizeOffset (NonEmptySet.flatten set)
src/Data/Array/Comfort/Shape.hs view
@@ -307,7 +307,7 @@  instance (Integral n) => Indexed (ZeroBased n) where    type Index (ZeroBased n) = n-   indices (ZeroBased len) = indices $ Shifted 0 len+   indices (ZeroBased len) = takeWhile (<len) $ iterate (+1) 0    unifiedOffset (ZeroBased len) = unifiedOffset $ Shifted 0 len    inBounds (ZeroBased len) ix = 0<=ix && ix<len @@ -354,7 +354,7 @@  instance (Integral n) => Indexed (OneBased n) where    type Index (OneBased n) = n-   indices (OneBased len) = indices $ Shifted 1 len+   indices (OneBased len) = takeWhile (<=len) $ iterate (+1) 1    unifiedOffset (OneBased len) = unifiedOffset $ Shifted 1 len    inBounds (OneBased len) ix = 0<ix && ix<=len