packages feed

bounded-array (empty) → 0.1.0.0

raw patch · 4 files changed

+114/−0 lines, 4 filesdep +arraydep +basesetup-changed

Dependencies added: array, base

Files

+ Data/Array/Bounded.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE DeriveTraversable          #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++module Data.Array.Bounded (+  BoundedArray+, (!)+, (//)+, indexBounded+, unboundedArray+, listArrayFill+, listArrayCycle+, accumArrayBounded+) where++import           Data.Array         hiding ((!), (//))+import           Data.Array.Base    (unsafeAccumArray, unsafeAt, unsafeReplace)+import           Data.Bifunctor     (first)+import           Data.List.NonEmpty (NonEmpty, cycle, toList)+import           Prelude            hiding (cycle)++newtype IntegralIndex i+  = IntegralIndex i+  deriving (Eq, Ord, Show, Bounded, Enum, Real, Integral, Num)++instance (Integral i) => Ix (IntegralIndex i) where+  range (a, b) =+    [a..b]+  index (a, _) i =+    fromIntegral i - fromIntegral a+  inRange (a, b) i =+    a <= i && i <= b++newtype BoundedArray i e+  = BoundedArray (Array (IntegralIndex i) e)+  deriving (Show, Eq, Ord, Functor, Foldable, Traversable)++indexBounded :: (Bounded i, Integral i) => i -> Int+indexBounded i =+  fromIntegral (i - minBound)++unboundedArray :: (Bounded i, Integral i, Ix i) => BoundedArray i e -> Array i e+unboundedArray (BoundedArray a) =+  ixmap (minBound, maxBound) IntegralIndex a++(!) :: (Bounded i, Integral i) => BoundedArray i e -> i -> e+BoundedArray a ! i =+  a `unsafeAt` indexBounded i++(//) :: (Bounded i, Integral i) => BoundedArray i e -> [(i, e)] -> BoundedArray i e+BoundedArray a // ies =+  BoundedArray . unsafeReplace a $ fmap (first indexBounded) ies++listArrayFill :: (Bounded i, Integral i) => e -> [e] -> BoundedArray i e+listArrayFill e =+  BoundedArray . listArray (minBound, maxBound) . (++ repeat e)++listArrayCycle :: (Bounded i, Integral i) => NonEmpty e -> BoundedArray i e+listArrayCycle =+  BoundedArray . listArray (minBound, maxBound) . toList . cycle++accumArrayBounded :: (Bounded i, Integral i) => (e -> a -> e) -> e -> [(i, a)] -> BoundedArray i e+accumArrayBounded f initial =+  BoundedArray . unsafeAccumArray f initial (minBound, maxBound) . fmap (first indexBounded)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Brian McKenna++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Brian McKenna nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bounded-array.cabal view
@@ -0,0 +1,19 @@+name:                bounded-array+version:             0.1.0.0+synopsis:            Arrays with a value for every index+description:         Arrays with a value for every index.+license:             BSD3+license-file:        LICENSE+author:              Brian McKenna+maintainer:          brian@brianmckenna.org+category:            Data+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Data.Array.Bounded+  other-extensions:    DeriveTraversable+                     , GeneralizedNewtypeDeriving+  build-depends:       base >=4.9 && <4.12+                     , array >=0.5 && <0.6+  default-language:    Haskell2010