[GHC] #15078: base: Customary type class laws (e.g. for Eq) and non-abiding instances (e.g. Float) should be documented
GHC
ghc-devs at haskell.org
Fri May 25 19:11:33 UTC 2018
#15078: base: Customary type class laws (e.g. for Eq) and non-abiding instances
(e.g. Float) should be documented
-------------------------------------+-------------------------------------
Reporter: sjakobi | Owner: Azel
Type: feature request | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Core Libraries | Version: 8.4.2
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4736
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by dfeuer):
Expanding a bit in another direction, I think it probably makes sense to
note that `Num` instances are typically expected to form rings. In fact,
the `signum` and `abs` functions suggest even more structure, although I
don't personally know what sort of structure that ''is''. I'd be very
hesitant to document any expectations beyond the ring laws, because there
are a number of exotic `Num` instances in the wild.
The best-behaved law-breaker here is `Natural`, which does not have a
sensible `negate` or `(-)`; it's a perfectly good semiring (more
specifically, a ''rig''), but we don't have a class corresponding to that.
As usual, `Float` and `Double` are truly flagrant law-breakers.
It might also be worth mentioning that types that are well-behaved
instances of both `Num` and `Ord` are ''not'' necessarily ordered rings.
In particular, `Int`, `Word`, `Int8`, `Word8`, etc., are not ordered
rings. As far as I know, the only `Num`+`Ord` instances in `base` that
implement ordered rings are `Integer` and `Rational`.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15078#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list