diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-11-13 20:18:24 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-11-13 20:18:24 +0100 |
commit | dd859ea30b187880e49c0cb005cc6006a1e3bbc1 (patch) | |
tree | 8a098b2ccd8774343ade7151d7984991b916fd7a /src | |
parent | 2cf7a229a6cda8f2adc2a5b1ad71473e822949bc (diff) |
Incoherent Shaped '[] instances (Num/Fractional)
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Array/Nested/Internal/Shaped.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs index 023f96c..f427041 100644 --- a/src/Data/Array/Nested/Internal/Shaped.hs +++ b/src/Data/Array/Nested/Internal/Shaped.hs @@ -195,15 +195,29 @@ instance (NumElt a, PrimElt a, Num a) => Num (Shaped sh a) where negate = arithPromoteShaped negate abs = arithPromoteShaped abs signum = arithPromoteShaped signum - fromInteger = error "Data.Array.Nested.fromInteger: No singletons available, use explicit sreplicateScal" + fromInteger = error "Data.Array.Nested.fromInteger: No singletons available, use explicit sreplicateScal/sscalar" + +instance {-# INCOHERENT #-} (NumElt a, PrimElt a, Num a) => Num (Shaped '[] a) where + (+) = arithPromoteShaped2 (+) + (-) = arithPromoteShaped2 (-) + (*) = arithPromoteShaped2 (*) + negate = arithPromoteShaped negate + abs = arithPromoteShaped abs + signum = arithPromoteShaped signum + fromInteger = sscalar . fromInteger instance (FloatElt a, NumElt a, PrimElt a, Num a) => Fractional (Shaped sh a) where - fromRational _ = error "Data.Array.Nested.fromRational: No singletons available, use explicit sreplicateScal" + fromRational _ = error "Data.Array.Nested.fromRational: No singletons available, use explicit sreplicateScal/sscalar" + recip = arithPromoteShaped recip + (/) = arithPromoteShaped2 (/) + +instance {-# INCOHERENT #-} (FloatElt a, NumElt a, PrimElt a, Fractional a) => Fractional (Shaped '[] a) where + fromRational = sscalar . fromRational recip = arithPromoteShaped recip (/) = arithPromoteShaped2 (/) instance (FloatElt a, NumElt a, PrimElt a, Num a) => Floating (Shaped sh a) where - pi = error "Data.Array.Nested.pi: No singletons available, use explicit sreplicateScal" + pi = error "Data.Array.Nested.pi: No singletons available, use explicit sreplicateScal/sscalar" exp = arithPromoteShaped exp log = arithPromoteShaped log sqrt = arithPromoteShaped sqrt |