Practical overview
When it fits
Use backprop when a Haskell program already expresses the computation or loss function and needs gradients for numerical optimization or parameter updates.
Who it is for
- Haskell developers building differentiable numerical programs.
- Developers implementing optimization or training code for numerical models.
Documented uses
- Compute a function’s derivative or gradient at chosen inputs.
- Obtain gradients for parameters in a model with matrix, vector, and scalar components.
- Use gradients as input to a numerical optimization or model-training routine.
Requirements & limits
- The documented project setup adds backprop through Cabal or package.yaml dependencies.
- The neural-network example relies on hmatrix-related operations and additional Haskell tooling, including lens accessors and Template Haskell.
- The library computes gradients; model definition, loss construction, and parameter-update logic remain part of the user's code.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Add backprop and compute a function’s gradient
Set up the library as a Haskell project dependency and apply automatic differentiation to a function.
Before you start
- A Haskell package using Cabal or package.yaml.
Steps
Add backprop to the package's build-depends field.
Import Numeric.Backprop.
Define a Haskell function, then use gradBP on the function and an input value to obtain its gradient.
Expected outcome
The project can evaluate a defined function and compute its gradient at an input.
Guide limitations
- The guide demonstrates a scalar example; it does not specify compiler or package-version requirements.
Compute gradients for a heterogeneous network loss
Follow the documented pattern for obtaining gradients of a network loss with respect to parameters of different types.
Before you start
- A Haskell project with backprop.
- The documented example uses hmatrix and hmatrix-backprop, lens accessors, and Template Haskell.
Steps
Represent network parameters with matrix and vector fields and make the network type an instance of Backprop.
Write a function that runs the network and a loss function that evaluates its output.
Apply gradBP to the loss function and network parameters to obtain their gradients.
Expected outcome
The loss gradient is available for the network’s parameter structure, including its weights and biases.
Guide limitations
- The example outlines adjusting parameters in the opposite direction of the gradient but does not give a complete training loop or update implementation.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 20 November 2026
- Original website title
- backprop - Home · Official homepage title · retained in its source language

