liveBook · Manning

Floating

As explained in Learn Haskell by Example

Floating is a Haskell type class for floating-point types that provide trigonometric, logarithmic, and related mathematical operations.

Floating is a Haskell type class for floating-point values such as Float and Double, supplying trigonometric, logarithmic, and related mathematical operations. section 10.1.1

Applying a trigonometric operation

Use sin with an explicitly typed Double when generating or processing a signal: sin (fromIntegral (1 :: Int)) :: Double produces 0.8414709848078965. section 10.1.1

Signal-processing code commonly represents samples, frequencies, and durations as Double. Floating-point calculations can then be converted to integral sample counts with round when a whole number is required. section 10.1.1

Listing 10.1 Types and helper functions for dealing with signals
type Sample = Double       #1

type Signal = [Sample]    #1  

type Hz = Double          #1

type Seconds = Double     #1

sampleRate :: Double     #2
sampleRate = 44100

samplesPerPeriod :: Hz -> Int
samplesPerPeriod hz = round $ sampleRate / hz            #3

samplesPerSecond :: Seconds -> Int
samplesPerSecond duration = round $
 duration * sampleRate       #4

Inspect the signal types and helper functions that use Double arithmetic before converting calculated sample counts to Int. section 10.1.1

How Learn Haskell by Example covers it

How deep it goes
Defines the role of floating-point mathematics and demonstrates sin, but does not detail the Floating class declaration.
Examples
Demonstrates Double-based signals, sample-rate calculations, round, and sin.
What it assumes
Assumes basic numeric types and arithmetic while introducing Fractional, RealFrac, and related numeric classes.
What you can do after
Apply floating-point operations to signal calculations and convert results into whole-number sample counts.
How it connects
Connects floating-point arithmetic with RealFrac, Fractional, Integral, and signal sampling.

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.