Adds missing Data.Num.Linear.* instances for Word, Integer, Natural, Float, Word8/16/32/64 Int8/16/32/64#467
Conversation
- Integer - Natural* - Word - Float - Int8/Int16/Int32/Int64 - Word8/Word16/Word32/Word64 (The Additive, Multiplicative, AddIdentity, MultIdentity, AdditiveGroup, Semiring, Ring, FromInteger and Num typeclasses) *: Natural does not have a Ring (nor Num) instance because it cannot satisfy the 'additive inverse' law. Fixes tweag#466
|
The |
6f55879 to
650930a
Compare
| instance (AddIdentity a) => Monoid (Sum a) where | ||
| mempty = Sum zero | ||
|
|
||
| {- ORMOLU_DISABLE -} |
There was a problem hiding this comment.
I took the liberty of re-ordering these by instance rather than by class because I believe it's easier on the eyes. Ormolu is disabled in this part of the code because it would add a newline between each deriving line. I hope you agree. If not, we can always change it back.
There was a problem hiding this comment.
Disabling Ormolu is a little unorthodox, but I must admit that in this case, it looks like it's worth it.
aspiwack
left a comment
There was a problem hiding this comment.
This all looks good. Thank you very much. I noticed that the CI hadn't ran yet. So I triggered it, and I'll (auto)merge when green.
| instance (AddIdentity a) => Monoid (Sum a) where | ||
| mempty = Sum zero | ||
|
|
||
| {- ORMOLU_DISABLE -} |
There was a problem hiding this comment.
Disabling Ormolu is a little unorthodox, but I must admit that in this case, it looks like it's worth it.
|
Actually, can I, instead, ask you to add the newline to the appropriate commit to avoid a silly commit? Sorry about the rather trivial request. |
650930a to
c0438dd
Compare
|
Ormolu/git should be happy now; of course the CI only runs after being approved once more. |
|
I'm guessing Github will keep requiring an approval for CI until you have at least one commit on master. I relaunched it. |
This PR fixes two (related) issues (#403 and #466):
Consumable/Dupable) instances are added forIntegerandNatural. This is safe since these types are represented as strict sum types whose elements are unlifed unboxed primitives so there is no way laziness might break linearity in there. (See also the last part of the discussion in #403)Data.Num.linear(Additive/AddIdentity/AdditiveGroup/Multiplicative/MultIdentity/Semiring/Ring/Num) for the general-purpose number types that exist in the Prelude/basewhich were still missing them:WordFloatIntegerNaturalWord8/Word16/Word32/Word64Int8/Int16/Int32/Int64Still missing are:
Ratio aandComplex a.Foreign.C.TypeslikeCInt/CFloatetc.Foreign.Ptrtypes likeIntPtr,WordPtr.Those could be added just as easily but because I was not 100% sure whether adding linear instances for them would be (morally) correct or have unintended consequences that might break linearity in ineffable ways, I left them alone for now.