Functional Programming in Learning Electromagnetic Theory
Scott N. Walck
TL;DR
The paper investigates using functional programming, especially Haskell, to teach and explore electromagnetic theory, treating EM as a field theory that benefits from precise, type-driven code. It encodes central EM concepts as types (e.g., ScalarField, VectorField, Position) and demonstrates vector calculus and Maxwell integrals through concrete Haskell implementations, including a Biot–Savart law model. By presenting numerical verifications of theorems such as Stokes' theorem and realistic problem settings (e.g., current loops), the work shows how computation can complement traditional analytics in pedagogy. The author argues that features of functional programming—strong typing, higher‑order functions, and referential transparency—facilitate understanding and reasoning in physics, with a forward-looking note on dependently typed languages as a potential future tool for physics and EM theory analysis and verification.
Abstract
Electromagnetic theory is central to physics. An undergraduate major in physics typically takes a semester or a year of electromagnetic theory as a junior or senior, and a graduate student in physics typically takes an additional semester or year at a more advanced level. In fall 2023, the author taught his undergraduate electricity and magnetism class using numerical methods in Haskell in parallel with traditional analytical methods. This article describes what functional programming has to offer to physics in general, and electromagnetic theory in particular. We give examples from vector calculus, the mathematical language in which electromagnetic theory is expressed, and electromagnetic theory itself.
