23
votes

The Haskell prelude and Standard Library define a number of useful type classes.

Is there a page somewhere that lists the minimum complete definition for all these classes?

2
Can you quantify what you mean by "standard library"? Are you referring to haskell98/haskell2010/base? GHC's boot libraries? Haskell Platform? - ivanm
ivanm, I'm not sure I know enough to know the difference. I just wanted to make any answer would include things like Monad and Arrow. - John F. Miller
You could rephrase it as something like "What is the minimum specification for the common Haskell type classes?". - Tikhon Jelvis

2 Answers

34
votes

This information can be found scattered around the Haskell language report as well as the GHC documentation, but in the interest of having an overview, I'm starting a CW answer for this.

Comparison

  • Eq: == or /=.
  • Ord: compare or <=.

Numbers

  • Num: All except either - or negate.
  • Real: toRational.
  • Integral: quotRem and toInteger.
  • Bits: .&., .|., xor, complement, either shift or both shiftL and shiftR, either rotate or both rotateL and rotateR, bitSize and isSigned.
  • Fractional: fromRational and either / or recip.
  • Floating: pi, exp, log, sin, cos, sinh, cosh, asin, acos, atan, asinh, acosh and atanh.
  • RealFrac: properFraction.
  • RealFloat: All except exponent, significand, scaleFloat and atan2.

Functors

Arrows

Serialization

  • Read: readsPrec (or, for GHC only, readPrec).
  • Show: show or showsPrec.

Misc

  • Enum: toEnum and fromEnum.
  • Bounded: Both minBound and maxBound.
  • Ix: range, index, inRange.
  • Monoid: mempty and mappend.
2
votes

The section in the Haskell Report about standard classes describes what you need to implement for each type class.