From dd859ea30b187880e49c0cb005cc6006a1e3bbc1 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 13 Nov 2024 20:18:24 +0100 Subject: Incoherent Shaped '[] instances (Num/Fractional) --- src/Data/Array/Nested/Internal/Shaped.hs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/Data/Array/Nested') 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 -- cgit v1.2.3-70-g09d2