This is my type:
import Numeric.AD
---
data Measurement a = Measurement !a !a
This is how I calculate a function on my type:
sqrtDiff :: Floating a => (forall a1. Floating a1 => a1 -> a1) -> a -> a -> a
sqrtDiff f a b = sqrt ((b**2) * diff f a ** 2)
newMeasurement :: Floating a => (forall a1. Floating a1 => a1 -> a1) -> Measurement a -> Measurement a
newMeasurement f (Measurement c d) = Measurement (f c) (sqrtDiff f c d)
If I have a = Measurement 3.0 0.1
and I want to compute the exponential I write: newMeasurement exp a
.
If I want to compute a function with more than 1 argument I can’t. I have to write another function, here an example with a function with 2 args.
nM :: Floating a => (forall a1. Floating a1 => [a1] -> a1) -> Measurement a -> Measurement a -> Measurement a
nM f (Measurement a b) (Measurement c d) = Measurement (f [a, c]) (sqrt (((g !! 0) * b)**2 + ((g !! 1) * d)**2))
where g = grad f [a, c]
If I want to compute a function with 3 args I have to write another function.