Reputation: 9805
One of the serious use case for units of measure is matrix operations: The inner product of a matrix a*b with c*d is only valid when b = c, etc....
However, I dont see any constructs for 'composite units' such as the one that would be required.
Do we have any way of having this checked by the type system in F# ?
Upvotes: 2
Views: 215
Reputation: 16782
disclaimer: sent from phone => can contain errors
I'd say that this check in some way can be achieved using UoM or phantom types:
[<Measure>] type s
type M<[<Measure>]'w, [<Measure>] 'h>() =
static member (*) (a : M<'a, 't>, b : M<'t, 'b>) : M<'a, 'b> = failwith "NYI"
let x = M<s ^ 3, s ^ 3>()
let y = M<s ^ 3, s>()
let z = x * y // M<s ^ 3, s>
However question is: how convinient it will be to use...
Upvotes: 4