-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Arrays where the index type is a function of the shape type
--
-- Arrays from the basic array package are already very powerful
-- compared with arrays in other languages. It provides arrays of any
-- dimension in a type safe and uniform way with free choice of the lower
-- bounds (0, 1, or whatever you like).
--
-- This package goes one step further: The shape and the index type are
-- different, but the index type is a type function of the shape type.
-- This offers much more flexibility and type safety.
--
-- Some examples are:
--
--
-- - Range: Allow dynamic choice of lower and upper array
-- bounds such as in the Arrays from the array package.
-- You can combine it with other shapes in other dimensions. It allows
-- you to describe the bounds of each dimension individually.
-- - Shifted: Describe array bounds by start index and length.
-- It is sometimes more natural to use these parameters. E.g. a
-- non-negative index type like Word cannot represent -1
-- and thus cannot encode an empty range starting with index
-- 0.
-- - Square: An 2D array where both dimensions always have
-- equal size.
-- - ZeroBased, OneBased: Arrays with fixed lower bound,
-- either 0 or 1, respectively.
-- - Arrays with indices like LT, EQ, GT and dummy
-- shape.
--
@package comfort-array
@version 0.0.1
module Data.Array.Comfort.Shape
class C sh where {
type family Index sh :: *;
}
indices :: C sh => sh -> [Index sh]
offset :: C sh => sh -> Index sh -> Int
uncheckedOffset :: C sh => sh -> Index sh -> Int
inBounds :: C sh => sh -> Index sh -> Bool
size :: C sh => sh -> Int
uncheckedSize :: C sh => sh -> Int
sizeOffset :: C sh => sh -> Index sh -> (Int, Int)
uncheckedSizeOffset :: C sh => sh -> Index sh -> (Int, Int)
-- | ZeroBased denotes a range starting at zero and has a certain
-- length.
newtype ZeroBased n
ZeroBased :: n -> ZeroBased n
[zeroBasedSize] :: ZeroBased n -> n
-- | OneBased denotes a range starting at zero and has a certain
-- length.
newtype OneBased n
OneBased :: n -> OneBased n
[oneBasedSize] :: OneBased n -> n
-- | Range denotes an inclusive range like those of the Haskell 98
-- standard Array type from the array package. E.g. the
-- shape type (Range Int32, Range Int64) is equivalent to the ix
-- type (Int32, Int64) for Arrays.
data Range n
Range :: n -> Range n
[rangeFrom, rangeTo] :: Range n -> n
-- | Shifted denotes a range defined by the start index and the
-- length.
data Shifted n
Shifted :: n -> Shifted n
[shiftedOffset, shiftedSize] :: Shifted n -> n
data sh0 (:+:) sh1
(:+:) :: sh0 -> sh1 -> (:+:) sh0 sh1
instance (GHC.Show.Show sh1, GHC.Show.Show sh0) => GHC.Show.Show (sh0 Data.Array.Comfort.Shape.:+: sh1)
instance (GHC.Classes.Eq sh1, GHC.Classes.Eq sh0) => GHC.Classes.Eq (sh0 Data.Array.Comfort.Shape.:+: sh1)
instance GHC.Show.Show n => GHC.Show.Show (Data.Array.Comfort.Shape.Shifted n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Data.Array.Comfort.Shape.Shifted n)
instance GHC.Show.Show n => GHC.Show.Show (Data.Array.Comfort.Shape.Range n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Data.Array.Comfort.Shape.Range n)
instance GHC.Show.Show n => GHC.Show.Show (Data.Array.Comfort.Shape.OneBased n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Data.Array.Comfort.Shape.OneBased n)
instance GHC.Show.Show n => GHC.Show.Show (Data.Array.Comfort.Shape.ZeroBased n)
instance GHC.Classes.Eq n => GHC.Classes.Eq (Data.Array.Comfort.Shape.ZeroBased n)
instance (Data.Array.Comfort.Shape.C sh0, Data.Array.Comfort.Shape.C sh1) => Data.Array.Comfort.Shape.C (sh0 Data.Array.Comfort.Shape.:+: sh1)
instance GHC.Real.Integral n => Data.Array.Comfort.Shape.C (Data.Array.Comfort.Shape.ZeroBased n)
instance GHC.Real.Integral n => Data.Array.Comfort.Shape.C (Data.Array.Comfort.Shape.OneBased n)
instance GHC.Real.Integral n => Data.Array.Comfort.Shape.C (Data.Array.Comfort.Shape.Shifted n)
instance Foreign.Storable.Storable n => Foreign.Storable.Storable (Data.Array.Comfort.Shape.Shifted n)
instance GHC.Arr.Ix n => Data.Array.Comfort.Shape.C (Data.Array.Comfort.Shape.Range n)
instance Foreign.Storable.Storable n => Foreign.Storable.Storable (Data.Array.Comfort.Shape.Range n)
instance Data.Array.Comfort.Shape.C ()
instance (Data.Array.Comfort.Shape.C sh0, Data.Array.Comfort.Shape.C sh1) => Data.Array.Comfort.Shape.C (sh0, sh1)
instance (Data.Array.Comfort.Shape.C sh0, Data.Array.Comfort.Shape.C sh1, Data.Array.Comfort.Shape.C sh2) => Data.Array.Comfort.Shape.C (sh0, sh1, sh2)
module Data.Array.Comfort.Storable.Internal
data Array sh a
Array :: sh -> ForeignPtr a -> Array sh a
[shape] :: Array sh a -> sh
[buffer] :: Array sh a -> ForeignPtr a
reshape :: sh1 -> Array sh0 a -> Array sh1 a
mapShape :: (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
(!) :: (C sh, Storable a) => Array sh a -> Index sh -> a
infixl 9 !
unsafeCreate :: (C sh, Storable a) => sh -> (Ptr a -> IO ()) -> Array sh a
unsafeCreateWithSize :: (C sh, Storable a) => sh -> (Int -> Ptr a -> IO ()) -> Array sh a
toList :: (C sh, Storable a) => Array sh a -> [a]
fromList :: (C sh, Storable a) => sh -> [a] -> Array sh a
vectorFromList :: (Storable a) => [a] -> Array (ZeroBased Int) a
map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b
createIO :: (C sh, Storable a) => sh -> (Ptr a -> IO ()) -> IO (Array sh a)
createWithSizeIO :: (C sh, Storable a) => sh -> (Int -> Ptr a -> IO ()) -> IO (Array sh a)
showIO :: (C sh, Show sh, Storable a, Show a) => Array sh a -> IO String
readIO :: (C sh, Storable a) => Array sh a -> Index sh -> IO a
toListIO :: (C sh, Storable a) => Array sh a -> IO [a]
fromListIO :: (C sh, Storable a) => sh -> [a] -> IO (Array sh a)
vectorFromListIO :: (Storable a) => [a] -> IO (Array (ZeroBased Int) a)
instance (Data.Array.Comfort.Shape.C sh, GHC.Show.Show sh, Foreign.Storable.Storable a, GHC.Show.Show a) => GHC.Show.Show (Data.Array.Comfort.Storable.Internal.Array sh a)
module Data.Array.Comfort.Storable
data Array sh a
shape :: Array sh a -> sh
(!) :: (C sh, Storable a) => Array sh a -> Index sh -> a
infixl 9 !
toList :: (C sh, Storable a) => Array sh a -> [a]
fromList :: (C sh, Storable a) => sh -> [a] -> Array sh a
vectorFromList :: (Storable a) => [a] -> Array (ZeroBased Int) a
map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b