1 Operations, Types, and Structs
1.1 Operations
1.1.1 Operations on Measures
It is syntactic sugar for using m+, m-, m*, m1/, and mexpt in prefix notation.
> (require typed/racket)
> (require typed/measures-with-dimensions)
> (m: 1 meter) - : Length-Real-Measure
(m: 1 meter)
> (m: 50 centimeter) - : Length-Real-Measure
(m: 50 centimeter)
> (m: 1 meter + 50 centimeter) - : Length-Real-Measure
(m: 3/2 meter)
> (m: 1 meter - 50 centimeter) - : Length-Real-Measure
(m: 1/2 meter)
> (m: 1 meter ^ 2) - : Measure
(m: 1 (usqr meter))
> (m: 1 meter ^ 2 + 100 centimeter ^ 2) - : Measure
(m: 101/100 (usqr meter))
> (m: 1 foot + 3 inch) - : Length-Real-Measure
(m: 5/4 foot)
> (m: 1 meter - 50 centimeter : Length-Real-Measure) - : Length-Real-Measure
(m: 1/2 meter)
procedure
m : Measureish
Note for typed racket users: when the typechecker typechecks m+, it doesn’t actually check that its arguments have the same dimensions (it does check at runtime). Instead it typechecks as returning a measure with a union of the dimensions of its arguments. For example, (m+ (make-measure 1 meter) (make-measure 1 second)) typechecks as something that could have either the length dimension or the time dimension. You can fix this by either requiring the type of the result to be what you want, or using inst to instantiate it for a certain dimension.
> (require typed/racket)
> (require typed/measures-with-dimensions)
> (ann (m+) Zero-Measure) - : Zero-Measure
(m: 0 1-unit)
> (m+ (m: 1 meter)) - : Length-Real-Measure
(m: 1 meter)
> (m+ (m: 1 meter) (m: 50 centimeter)) - : Length-Real-Measure
(m: 3/2 meter)
> (m: 1 foot + 3 inch) - : Length-Real-Measure
(m: 5/4 foot)
> ((inst m+ Length-Dimension) (m: 1 meter) (m: 50 centimeter)) - : Length-Real-Measure
(m: 3/2 meter)
procedure
m : Measureish
> (require typed/racket)
> (require typed/measures-with-dimensions)
> (m- (m: 1 meter)) - : Length-Real-Measure
(m: -1 meter)
> (m: 1 meter - 50 centimeter) - : Length-Real-Measure
(m: 1/2 meter)
procedure
m : Measureish
procedure
(m1/ m) → Number-Measure
m : Number-Measureish
procedure
(mexpt m1 m2) → Number-Measure
m1 : Number-Measureish m2 : Number-Measureish
procedure
(mabs m) → Real-Measure
m : Real-Measure
procedure
m : Measure u : Unitish (convert n u1 u2) → Measure n : (U Number (Vectorof Real)) u1 : Unitish u2 : Unitish
> (require typed/racket)
> (require typed/measures-with-dimensions)
> (convert (m: 1 meter) centimeter) - : Length-Real-Measure
(m: 100 centimeter)
> (convert 1 meter centimeter) - : Length-Measure
(m: 100 centimeter)
procedure
m1 : Measureish m : Measureish
> (require typed/racket)
> (require typed/measures-with-dimensions)
> (measure=? (m: 1 meter) (m: 100 centimeter)) - : Boolean
#t
> (measure=? (m: 1 meter) (m: 1 kilogram)) - : Boolean
#f
> (measure=? (m: 1 radian) (m: 1 degree)) - : Boolean
#f
procedure
m : Measureish
procedure
(measure->num/vec m) → (U Number (Vectorof Real))
m : Measureish
procedure
(measure->number m) → Number
m : Number-Measureish
procedure
(measure->real m) → Real
m : Real-Measureish
procedure
(measure->vector m) → (Vectorof Real)
m : Vector-Measureish
1.1.2 Operations on Units and Dimensions
procedure
u : Unitish
procedure
u : Unitish
procedure
u1 : Unitish u : Unitish
procedure
u : Unitish n : Exact-Rational
procedure
u : Unitish
procedure
u : Unitish
procedure
(unit-rename u n) → Unit
u : Unit n : Any
procedure
u1 : Unitish u : Unitish
procedure
u : Dimension
procedure
d : Dimension
procedure
d1 : Dimension d : Dimension
procedure
d : Dimension n : Exact-Rational
procedure
(dimension=? d1 d ...) → Boolean
d1 : Dimension d : Dimension
1.2 Types and Structs
type
type
(Measureof n u)
type
type
type
(Number-Measureof u)
type
(Vector-Measureof u)
type
type
type
type
type
type
(Unitof d)
type
type
type
struct
M-expt : Integer L-expt : Integer T-expt : Integer Q-expt : Integer Θ-expt : Integer
procedure
(make-dimension #:M^ M-expt #:L^ L-expt #:T^ T-expt #:Q^ Q-expt #:Θ^ Θ-expt) → Dimension M-expt : Integer L-expt : Integer T-expt : Integer Q-expt : Integer Θ-expt : Integer
struct
name : Any scalar : Positive-Real dimension : Dimension
struct
number : (U Number (Vectorof Real)) unit : Unit sig-figs : Sig-Figs
procedure
(make-measure number unit [sig-figs]) → Measure
number : (U Number (Vectorof Real)) unit : Unit sig-figs : Sig-Figs = +inf.0
procedure
(measure-dimension m) → Dimension
m : Measure