aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Mixed.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-05-21 11:50:39 +0200
committerTom Smeding <tom@tomsmeding.com>2024-05-21 11:50:47 +0200
commit40022f56cfcf79d56abecf4055d9a5cc3a07447e (patch)
treed278b3d0ee91e096f3568b3c17b17108813f2b06 /src/Data/Array/Mixed.hs
parent3d2e4a567668ea951e629834e6871a3f144c1b84 (diff)
Add Ord instances on 0-dimensional arrays
This is very conservative; of course a law-abiding Ord instance can be defined on full multi-dimensional arrays, but such an instance would be lexicographical (anything else is even stranger), and that is potentially unexpected and definitely does not play well with the other numeric classes.
Diffstat (limited to 'src/Data/Array/Mixed.hs')
-rw-r--r--src/Data/Array/Mixed.hs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/Data/Array/Mixed.hs b/src/Data/Array/Mixed.hs
index 320a393..baa9575 100644
--- a/src/Data/Array/Mixed.hs
+++ b/src/Data/Array/Mixed.hs
@@ -289,6 +289,9 @@ type XArray :: [Maybe Nat] -> Type -> Type
newtype XArray sh a = XArray (S.Array (Rank sh) a)
deriving (Show, Eq)
+-- | Only on scalars, because lexicographical ordering is strange on multi-dimensional arrays.
+deriving instance (Ord a, Storable a) => Ord (XArray '[] a)
+
zeroIxX :: StaticShX sh -> IIxX sh
zeroIxX ZKX = ZIX
zeroIxX (_ :!% ssh) = 0 :.% zeroIxX ssh