liveBook · Manning

Integral

As explained in Learn Haskell by Example

Integral is a Haskell type class for whole-number types that support integer division, remainders, and related conversions.

Integral is the Haskell type class for whole-number types. It provides integer division, remainders, related division operations, and conversion to Integer. section 10.1.1

Its main operations include:

  • Contrast Integral division with Fractional division, where (/) and recip operate on floating-point values. section 10.5

Counting audio samples

A sample count cannot contain half a sample, so convert a calculated Double with round: samplesPerPeriod hz = round $ sampleRate / hz and samplesPerSecond duration = round $ duration * sampleRate. Both functions return Int. section 10.1.1

How Learn Haskell by Example covers it

How deep it goes
Defines the class methods, superclass constraints, instances, and conversions while stopping short of detailed division semantics.
Examples
Uses audio sample counts, round, Int, Integer, div, and interactive type and class queries.
What it assumes
Builds on basic arithmetic and Num while introducing numeric type-class relationships through concrete Haskell expressions.
What you can do after
Apply Integral operations to countable values and convert between whole-number and floating-point representations.
How it connects
Connects Integral with Num, Real, Enum, RealFrac, Fractional, and Integer conversion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.