Open
Description
Was showing off nesting, simplest example I could think of, oops.
tldr: ad
4.3.2.1, ghc
8.0.1, diff (\x -> diff (*x) 1) 1
gets a type error.
$ cabal update
Downloading the latest package list from hackage.haskell.org
$ cabal install --user ad
Resolving dependencies...
Downloading base-orphans-0.5.4...
...
Installed free-4.12.4
Downloading ad-4.3.2.1...
Configuring ad-4.3.2.1...
Building ad-4.3.2.1...
Installed ad-4.3.2.1
$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :m + Numeric.AD
Prelude Numeric.AD> diff (*2) 1
2
Prelude Numeric.AD> diff sin 0
1.0
Prelude Numeric.AD> diff (\x -> diff (*x) 1) 1
<interactive>:6:20: error:
• Occurs check: cannot construct the infinite type:
a ~ AD s (Numeric.AD.Internal.Forward.Forward a)
Expected type: AD
s1
(Numeric.AD.Internal.Forward.Forward
(AD s (Numeric.AD.Internal.Forward.Forward a)))
Actual type: AD s (Numeric.AD.Internal.Forward.Forward a)
• In the second argument of ‘(*)’, namely ‘x’
In the first argument of ‘diff’, namely ‘(* x)’
In the expression: diff (* x) 1
• Relevant bindings include
x :: AD s (Numeric.AD.Internal.Forward.Forward a)
(bound at <interactive>:6:8)
it :: a (bound at <interactive>:6:1)
This happens even without nesting.
> diff (pi*) 1
3.141592653589793
> (\x -> diff (x*) 1) pi
error: ...
> let x=pi in diff (x*) 1
3.141592653589793
and yes, I know auto
makes it okay
Prelude Numeric.AD> diff (\x -> diff (auto x*) 2) 3
1
Prelude Numeric.AD> (\x -> diff (auto x*) 2) 3
3
But it's still a pretty big wart on an otherwise lovely countenance.