Skip to content

Instantly share code, notes, and snippets.

@crabmusket
Last active December 27, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crabmusket/7245302 to your computer and use it in GitHub Desktop.
Save crabmusket/7245302 to your computer and use it in GitHub Desktop.
Convenient constant arithmetic for Haskell's Dimensional package.
module Numeric.Units.Dimensional.ConstantArithmetic where
import qualified Prelude
import qualified Numeric.Units.Dimensional
import Numeric.Units.Dimensional.Prelude
a *. b = a * (b *~ one)
a .* b = (a *~ one) * b
a .*. b = (a *~ one) * (b *~ one)
a /. b = a / (b *~ one)
a ./ b = (a *~ one) / b
a ./. b = (a *~ one) / (b *~ one)
a +. b = a + (b *~ one)
a .+ b = (a *~ one) + b
a .+. b = (a *~ one) + (b *~ one)
a -. b = a - (b *~ one)
a .- b = (a *~ one) - b
a .-. b = (a *~ one) - (b *~ one)
squared a = a ^ pos2
cubed a = a ^ pos3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment