Valid types in Numeric.AD functions

I have little success wrapping my head around the basic plumbing types involved in the package ad. For example, the following works just fine:

import Numeric.AD

ex :: Num a => [a] -> a
ex [x, y] = x + 2*y

> grad ex [1.0, 1.0]
[1.0, 2.0]

where gradhas type:

grad
  :: (Num a, Traversable f) =>
     (forall (s :: * -> *). Mode s => f (AD s a) -> AD s a)
     -> f a -> f a

If I change the type signature exto [Double] -> Doubleand try to do the same, I get

Couldn't match expected type `AD s a0' with actual type `Double'
Expected type: f0 (AD s a0) -> AD s a0
  Actual type: [Double] -> Double

The same behavior occurs when you replace Doubleany constructor of any type with the type *that creates the instance Num.

Traversable f , grad [AD s a] -> AD s a Mode - , Reverse. , , grad ad Mode. , ; , / Num a => [a] -> a [Double] -> Double.

[Double] -> Double grad? : [Double] -> Double ex ?

(, )

+5
1

ad, grad [AD s a] -> AD s a, , [Double] -> Double, Double ad - .

Num , ad Num, ex -

ex :: (Mode s, Fractional a) => [AD s a] -> AD s a

ex , ,

ex :: Mode s => [AD s Double] -> AD s Double
+6

All Articles