Learn Physics With Functional Programming: A Ha... Apr 2026

Learn Physics with Functional Programming: A Haskell-Based Approach

A physical state (position, velocity) can be defined as a immutable record. Laws as Functions: Newton’s Second Law ( Learn Physics with Functional Programming: A Ha...

The trajectory of a particle over time can be modeled as a fold or scan over a sequence of time steps, reflecting the cumulative nature of integration. 3. Implementation Example: Projectile Motion Double) type State = (Vector

type Vector = (Double, Double) type State = (Vector, Vector) -- (Position, Velocity) applyGravity :: Double -> State -> State applyGravity dt ((x, y), (vx, vy)) = let g = -9.81 newVy = vy + g * dt newX = x + vx * dt newY = y + vy * dt in ((newX, newY), (vx, newVy)) Use code with caution. Vector) -- (Position

In an imperative style, one might loop through time and update a y variable. In Haskell, we define the physics as a pure function: