packages feed

n-tuple 0.0.0 → 0.0.1

raw patch · 2 files changed

+8/−5 lines, 2 files

Files

n-tuple.cabal view
@@ -1,5 +1,5 @@ name:                n-tuple-version:             0.0.0+version:             0.0.1 synopsis:            Homogeneous tuples of arbitrary length. -- description: homepage:            https://github.com/athanclark/n-tuple#readme
src/Data/NTuple.hs view
@@ -11,6 +11,7 @@   , empty   , proj   , incl+  , toVector   , -- * Proxies     _1   , _2@@ -28,14 +29,14 @@ import qualified Data.Vector as V  import GHC.TypeLits-import Data.Proxy (Proxy)+import Data.Proxy (Proxy (..)) import Data.List (intercalate) import Data.Singletons.Prelude import Data.Singletons.Prelude.Ord   newtype NTuple (size :: Nat) a = NTuple-  { getNTuple :: Vector a+  { toVector :: Vector a   }  @@ -47,22 +48,24 @@ empty = NTuple V.empty  +-- | Project an element out of the tuple proj :: ( n <= size         , (n :> 0) ~ True         , KnownNat n         )-      => Proxy n+      => Proxy n -- ^ The index       -> NTuple size a       -> a proj p (NTuple xs) = xs V.! (fromInteger (natVal p) - 1)  +-- | Include an element to the tuple, overwriting on an existing index incl :: ( n <= (size + 1)         , (n :> 0) ~ True         , KnownNat n         , size' ~ If (n :== (size + 1)) (size + 1) size         )-     => Proxy n+     => Proxy n -- ^ The index      -> a      -> NTuple size a      -> NTuple size' a