dimensions 1.0.0.0 → 1.0.1.1
raw patch · 3 files changed
+45/−10 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Numeric.Dimensions.Idxs: instance forall k (n :: k). (Data.Typeable.Internal.Typeable k, Data.Typeable.Internal.Typeable n) => Data.Data.Data (Numeric.Dimensions.Idxs.Idx n)
- Numeric.Tuple.Lazy: instance (Data.Semigroup.Semigroup (Numeric.Tuple.Lazy.Tuple xs), Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All GHC.Base.Monoid xs) => GHC.Base.Monoid (Numeric.Tuple.Lazy.Tuple xs)
- Numeric.Tuple.Lazy: instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Numeric.Tuple.Lazy.Id a)
- Numeric.Tuple.Lazy: instance Numeric.Type.List.All Data.Semigroup.Semigroup xs => Data.Semigroup.Semigroup (Numeric.Tuple.Lazy.Tuple xs)
- Numeric.Tuple.Strict: instance (Data.Semigroup.Semigroup (Numeric.Tuple.Strict.Tuple xs), Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All GHC.Base.Monoid xs) => GHC.Base.Monoid (Numeric.Tuple.Strict.Tuple xs)
- Numeric.Tuple.Strict: instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Numeric.Tuple.Strict.Id a)
- Numeric.Tuple.Strict: instance Numeric.Type.List.All Data.Semigroup.Semigroup xs => Data.Semigroup.Semigroup (Numeric.Tuple.Strict.Tuple xs)
+ Numeric.Dimensions.Dims: class KnownXNatTypes xds => XDimensions (xds :: [XNat])
+ Numeric.Dimensions.Dims: constrainDims :: XDimensions xds => Dims (ds :: [k]) -> Maybe (Dims xds)
+ Numeric.Dimensions.Dims: instance (Numeric.Dimensions.Dims.XDimensions xs, Numeric.Dim.KnownDim m) => Numeric.Dimensions.Dims.XDimensions (Numeric.Dim.XN m : xs)
+ Numeric.Dimensions.Dims: instance (Numeric.Dimensions.Dims.XDimensions xs, Numeric.Dim.KnownDim n) => Numeric.Dimensions.Dims.XDimensions (Numeric.Dim.N n : xs)
+ Numeric.Dimensions.Dims: instance Numeric.Dimensions.Dims.XDimensions '[]
+ Numeric.Dimensions.Idxs: instance forall k (n :: k). (Data.Typeable.Internal.Typeable n, Data.Typeable.Internal.Typeable k) => Data.Data.Data (Numeric.Dimensions.Idxs.Idx n)
+ Numeric.Tuple.Lazy: instance (GHC.Base.Semigroup (Numeric.Tuple.Lazy.Tuple xs), Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All GHC.Base.Monoid xs) => GHC.Base.Monoid (Numeric.Tuple.Lazy.Tuple xs)
+ Numeric.Tuple.Lazy: instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.Tuple.Lazy.Id a)
+ Numeric.Tuple.Lazy: instance Numeric.Type.List.All GHC.Base.Semigroup xs => GHC.Base.Semigroup (Numeric.Tuple.Lazy.Tuple xs)
+ Numeric.Tuple.Strict: instance (GHC.Base.Semigroup (Numeric.Tuple.Strict.Tuple xs), Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All GHC.Base.Monoid xs) => GHC.Base.Monoid (Numeric.Tuple.Strict.Tuple xs)
+ Numeric.Tuple.Strict: instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.Tuple.Strict.Id a)
+ Numeric.Tuple.Strict: instance Numeric.Type.List.All GHC.Base.Semigroup xs => GHC.Base.Semigroup (Numeric.Tuple.Strict.Tuple xs)
- Numeric.Dim: data Nat :: *
+ Numeric.Dim: data Nat
Files
- dimensions.cabal +1/−1
- src/Numeric/Dim.hs +8/−8
- src/Numeric/Dimensions/Dims.hs +36/−1
dimensions.cabal view
@@ -1,5 +1,5 @@ name: dimensions-version: 1.0.0.0+version: 1.0.1.1 cabal-version: >=1.22 build-type: Simple license: BSD3
src/Numeric/Dim.hs view
@@ -29,9 +29,9 @@ -- -- This module is based on `GHC.TypeLits` and re-exports its functionality. -- It provides `KnownDim` class that is similar to `KnownNat`, but keeps--- `Int`s instead of `Integer`s;--- Also it provides `Dim` data family serving as a customized `Proxy` type--- and a singleton suitable for recovering an instance of the `KnownDim` class.+-- `Word`s instead of `Integer`s;+-- Also it provides `Dim` data type serving as a singleton+-- suitable for recovering an instance of the `KnownDim` class. -- A set of utility functions provide inference functionality, so -- that `KnownDim` can be preserved over some type-level operations. --@@ -62,7 +62,7 @@ -- their @Word@ counterparts. , plusDim, minusDim, minusDimM, timesDim, powerDim -- * Re-export part of `GHC.TypeLits` for convenience- , Nat, CmpNat, type (+), type (-), type (*), type (^)+ , TL.Nat, TL.CmpNat, type (TL.+), type (TL.-), type (TL.*), type (TL.^) , MinDim, FixedDim, inferDimLE -- * Inferring kind of type-level dimension , KnownDimKind (..), DimKind (..)@@ -73,7 +73,7 @@ import Data.Type.Equality import GHC.Base (Type) import GHC.Exts (Constraint, Proxy#, proxy#, unsafeCoerce#)-import GHC.TypeLits+import GHC.TypeLits as TL import Numeric.Type.Evidence @@ -318,7 +318,7 @@ sameDim' :: forall (x :: Nat) (y :: Nat) p q . (KnownDim x, KnownDim y) => p x -> q y -> Maybe (Evidence (x ~ y))-sameDim' _ _ = sameDim' (dim @Nat @x) (dim @Nat @y)+sameDim' _ _ = sameDim (dim @Nat @x) (dim @Nat @y) {-# INLINE sameDim' #-} -- | Ordering of dimension values.@@ -377,11 +377,11 @@ | otherwise = Nothing {-# INLINE minusDimM #-} -timesDim :: Dim n -> Dim m -> Dim ((*) n m)+timesDim :: Dim n -> Dim m -> Dim ((TL.*) n m) timesDim (DimSing a) (DimSing b) = unsafeCoerce# (a * b) {-# INLINE timesDim #-} -powerDim :: Dim n -> Dim m -> Dim ((^) n m)+powerDim :: Dim n -> Dim m -> Dim ((TL.^) n m) powerDim (DimSing a) (DimSing b) = unsafeCoerce# (a ^ b) {-# INLINE powerDim #-}
src/Numeric/Dimensions/Dims.hs view
@@ -22,6 +22,7 @@ {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE UndecidableSuperClasses #-} {-# LANGUAGE ViewPatterns #-} ----------------------------------------------------------------------------- -- |@@ -39,7 +40,7 @@ ----------------------------------------------------------------------------- module Numeric.Dimensions.Dims- ( Dims, SomeDims (..), Dimensions (..)+ ( Dims, SomeDims (..), Dimensions (..), XDimensions (..) , TypedList ( Dims, XDims, AsXDims, KnownDims , U, (:*), Empty, TypeList, Cons, Snoc, Reverse) , listDims, someDimsVal, totalDim, totalDim'@@ -125,6 +126,10 @@ -- Hide all information about Dimensions inside data SomeDims = forall (ns :: [Nat]) . SomeDims (Dims ns) +-- | Put runtime evidence of `Dims` value inside function constraints.+-- Similar to `KnownDim` or `KnownNat`, but for lists of numbers.+-- Normally, the kind paramater is `Nat` (known dimenionality)+-- or `XNat` (either known or constrained dimensionality). class Dimensions (ds :: [k]) where -- | Get dimensionality of a space at runtime, -- represented as a list of `Dim`.@@ -155,6 +160,36 @@ instance (KnownDim d, Dimensions ds) => Dimensions (d ': ds :: [k]) where dims = dim :* dims {-# INLINE dims #-}++-- | Analogous to `Dimensions`, but weaker and more specific (list of `XNat`).+-- This class is used to check if an existing fixed `Dims` satisfy+-- constraints imposed by some interface (e.g. all dimensions are greater than 2).+-- It is weaker than `Dimensions` in that it only requires knowledge of constraints+-- rather than exact dimension values.+class KnownXNatTypes xds => XDimensions (xds :: [XNat]) where+ -- | Given a `Dims`, test if its runtime value satisfies constraints imposed by+ -- @XDimensions@, and returns it back being `XNat`-indexed on success.+ --+ -- This function allows to guess safely individual dimension values,+ -- as well as the length of the dimension list.+ constrainDims :: Dims (ds :: [k]) -> Maybe (Dims xds)++instance XDimensions '[] where+ constrainDims U = Just U+ constrainDims _ = Nothing+ {-# INLINE constrainDims #-}++instance (XDimensions xs, KnownDim m) => XDimensions (XN m ': xs) where+ constrainDims (d :* ds) = case constrain d of+ Nothing -> Nothing+ Just xd -> (xd :*) <$> constrainDims ds+ constrainDims Empty = Nothing++instance (XDimensions xs, KnownDim n) => XDimensions (N n ': xs) where+ constrainDims (d :* ds)+ | unsafeCoerce# d == dimVal' @n = (Dn D :*) <$> constrainDims ds+ | otherwise = Nothing+ constrainDims Empty = Nothing -- | Convert `Dims xs` to a plain haskell list of dimension sizes @O(1)@.