I would like to construct a type to handle simple error propagation.
My type is:
data Measurement a = Measurement !a !a
One argument represents the value of the measurement and the other the error.
I want to make it an instance of Num, but I want it to have this behaviour:
– If I add it to a Num type, I only want the value to be added to the first argument
k = Measurement 3.0 0.1
k + 3.0 -- should give Measurement 6.0 0.1
– if I add it to a Measurement, I want the sum of every argument
k = Measurement 3.0 0.1
j = Measurement 4.0 0.2
k + j -- Measurement 7.0 0.3
I don’t understand how to do this, in julia I should simply overload the operator (+) to handle all possible cases.
Suggestions?