I'm in need of a Grouping instance for Double. I'm not particularly worried about what happens with the different representations of NaNs, or with negative zeros, so I think I can get away with this:
import GHC.Float (castFloatToWord32, castDoubleToWord64)
instance Grouping Float where grouping = contramap castFloatToWord32 grouping
instance Grouping Double where grouping = contramap castDoubleToWord64 grouping
Any comments about my implementation are more than welcome, because have been cargo-culting examples from elsewhere in the code and can't say that I fully understand what I am doing.
I'd guess that groupingWord64 would work in my orphan instances (instead of grouping) if it was exported.
The functions from GHC.Float were introduced in GHC 8.4 by #4092, and Stack Overflow has a question that may contain solutions for earlier GHCs (but I haven't actually tried any of them).
I'm in need of a
Groupinginstance forDouble. I'm not particularly worried about what happens with the different representations of NaNs, or with negative zeros, so I think I can get away with this:Any comments about my implementation are more than welcome, because have been cargo-culting examples from elsewhere in the code and can't say that I fully understand what I am doing.
I'd guess that
groupingWord64would work in my orphan instances (instead ofgrouping) if it was exported.The functions from GHC.Float were introduced in GHC 8.4 by #4092, and Stack Overflow has a question that may contain solutions for earlier GHCs (but I haven't actually tried any of them).