I want to be able to do this:
let duration = 1 + 2 + 3
with the following types and functions (a
This isn't possible directly within F#. There isn't a way to have the "auto-conversion" succeed directly without specifying the conversion for the types. You would have to explicitly call your conversion functions (seconds_per_minute
, etc).
However, Phil Trelford demonstrated a mechanism by which you could create runtime classes which do support this, though with slightly different syntax. Using his types, you could write:
let duration = 1.0 * SI.hours + 2.0 * SI.minutes + 3.0 * SI.seconds