Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum specification for Haskell library type classes?

Tags:

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?

like image 236
John F. Miller Avatar asked Nov 30 '11 01:11

John F. Miller


People also ask

What are type classes in Haskell?

What's a typeclass in Haskell? A typeclass defines a set of methods that is shared across multiple types. For a type to belong to a typeclass, it needs to implement the methods of that typeclass. These implementations are ad-hoc: methods can have different implementations for different types.

What is an instance of a Haskell type class?

An instance of a class is an individual object which belongs to that class. In Haskell, the class system is (roughly speaking) a way to group similar types. (This is the reason we call them "type classes"). An instance of a class is an individual type which belongs to that class.

What is deriving show in Haskell?

Deriving means that your data type is automatically able to "derive" instances for certain type classes. In this case BaseballPlayer derives Show which means we can use any function that requires an instance of Show to work with BaseballPlayer .


1 Answers

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

  • Functor: fmap.
  • Applicative: pure and <*>.
  • Monad: >>= and return.
  • MonadPlus: mplus and mzero.
  • MonadFix: mfix.
  • Foldable: foldMap or foldr.
  • Traversable: traverse or sequenceA.

Arrows

  • Category: . and id.
  • Arrow: arr and first.
  • ArrowZero: zeroArrow.
  • ArrowPlus: <+>.
  • ArrowChoice: left.
  • ArrowApply: app.
  • ArrowLoop: loop.

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.
like image 124
6 revs, 2 users 99% Avatar answered Oct 17 '22 06:10

6 revs, 2 users 99%