packages feed

fixed-length 0.2 → 0.2.1

raw patch · 2 files changed

+46/−14 lines, 2 filesdep +storable-recordPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: storable-record

API changes (from Hackage documentation)

+ Data.FixedLength: curry :: Natural n => (T n a -> b) -> Curried n a b
+ Data.FixedLength: indexFromNum :: Natural n => Word -> Maybe (Index n)
+ Data.FixedLength: infixr 5 !:
+ Data.FixedLength: instance (Type.Data.Num.Unary.Natural n, Foreign.Storable.Storable a) => Foreign.Storable.Storable (Data.FixedLength.T n a)
+ Data.FixedLength: type family Curried n a b
- Data.FixedLength: head :: (Positive n) => T n a -> a
+ Data.FixedLength: head :: Positive n => T n a -> a
- Data.FixedLength: switchL :: (a -> T n a -> b) -> (T (Succ n) a -> b)
+ Data.FixedLength: switchL :: (a -> T n a -> b) -> T (Succ n) a -> b
- Data.FixedLength: toList :: (Natural n) => T n a -> [a]
+ Data.FixedLength: toList :: Natural n => T n a -> [a]
- Data.FixedLength: uncurry :: (Natural n) => Curried n a b -> T n a -> b
+ Data.FixedLength: uncurry :: Natural n => Curried n a b -> T n a -> b

Files

fixed-length.cabal view
@@ -1,5 +1,5 @@ Name:             fixed-length-Version:          0.2+Version:          0.2.1 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -25,7 +25,7 @@ Build-Type:       Simple  Source-Repository this-  Tag:         0.2+  Tag:         0.2.1   Type:        darcs   Location:    http://hub.darcs.net/thielema/fixed-length/ @@ -36,6 +36,7 @@ Library   Build-Depends:     tfp >=1.0 && <1.1,+    storable-record >=0.0.3 && <0.1,     non-empty >=0.2 && <0.4,     utility-ht >=0.0.1 && <0.1,     base >=4 && <5
src/Data/FixedLength.hs view
@@ -6,13 +6,13 @@    Index, Zero, Succ(Stop, Succ),    toList, showsPrec,    map, zipWith, sequenceA, repeat,-   index, update, indices, indicesInt, numFromIndex,+   index, update, indices, indicesInt, numFromIndex, indexFromNum,    GE1, GE2, GE3, GE4, GE5, GE6, GE7, GE8,    i0, i1, i2, i3, i4, i5, i6, i7,    fromFixedList, toFixedList,    (!:), end, singleton,    viewL, switchL, head, tail, switchEnd,-   Curried, uncurry,+   Curried, curry, uncurry,    minimum, maximum,    ) where @@ -20,6 +20,10 @@ import Type.Data.Num.Unary.Literal (U1) import Type.Data.Num.Unary (Positive, Natural, switchNat) +import qualified Foreign.Storable.FixedArray as StoreArray+import qualified Foreign.Storable.Traversable as StoreTrav+import Foreign.Storable (Storable, sizeOf, alignment, poke, peek)+ import qualified Data.NonEmpty as NonEmpty import qualified Data.Empty as Empty @@ -30,6 +34,7 @@ import Control.Applicative (Applicative, liftA2) import Data.Traversable (Traversable, foldMapDefault) import Data.Foldable (Foldable, foldMap)+import Data.Maybe (Maybe(Nothing, Just)) import Data.List ((++)) import Data.Word (Word) @@ -41,7 +46,7 @@ import Text.Show.HT (concatS)  import qualified Prelude as P-import Prelude (Functor, fmap, Show, ShowS, Int, (+), error)+import Prelude (Functor, fmap, Show, ShowS, Int, (+), (-), error)   type family List n :: * -> *@@ -67,7 +72,7 @@  infixr 5 !: -(!:) :: a -> T n a -> T (Unary.Succ n) a+(!:) :: {- (Natural n) => -} a -> T n a -> T (Unary.Succ n) a x !: Cons xs = Cons $ NonEmpty.Cons x xs  viewL :: T (Unary.Succ n) a -> (a, T n a)@@ -247,9 +252,20 @@             Succ m -> 1 + numFromIndex m)  -newtype Compare a n =-           Compare {runCompare :: Index n -> Index n -> a}+newtype+   IndexFromNum n = IndexFromNum {runIndexFromNum :: Word -> Maybe (Index n)} +indexFromNum :: Natural n => Word -> Maybe (Index n)+indexFromNum =+   runIndexFromNum $+   switchNat+      (IndexFromNum $ \ _k -> Nothing)+      (IndexFromNum $ \k ->+         if k==0 then Just i0 else fmap succ $ indexFromNum (k-1))+++newtype Compare a n = Compare {runCompare :: Index n -> Index n -> a}+ instance (Natural n) => Eq (Index n) where    (==) =       runCompare $@@ -297,19 +313,34 @@   -newtype-   Uncurry a b n =-      Uncurry {-         runUncurry :: Curried n a b -> T n a -> b-      }- type family Curried n a b type instance Curried Unary.Zero a b = b type instance Curried (Unary.Succ n) a b = a -> Curried n a b +newtype Curry a b n = Curry {runCurry :: (T n a -> b) -> Curried n a b}++curry :: (Unary.Natural n) => (T n a -> b) -> Curried n a b+curry =+   runCurry $+   Unary.switchNat+      (Curry $ ($end))+      (Curry $ \f a -> curry $ \xs -> f (a!:xs))++newtype Uncurry a b n = Uncurry {runUncurry :: Curried n a b -> T n a -> b}+ uncurry :: (Unary.Natural n) => Curried n a b -> T n a -> b uncurry =    runUncurry $    Unary.switchNat       (Uncurry switchEnd)       (Uncurry $ \f -> switchL (\x -> uncurry (f x)))+++undefinedElem :: T n a -> a+undefinedElem _ = error "touched element by accident"++instance (Natural n, Storable a) => Storable (T n a) where+   sizeOf xs = StoreArray.sizeOfArray (P.length $ toList xs) (undefinedElem xs)+   alignment = alignment . undefinedElem+   peek = StoreTrav.peekApplicative+   poke = StoreTrav.poke