在我最近的这个答案中,我碰巧打开了这个老板栗(这个程序太旧了,其中一半是莱布尼兹在十七世纪写的,七十年代由我父亲在电脑上写的).我会省去现代的位以节省空间.
class Differentiable f where
type D f :: * -> *
newtype K a x = K a
newtype I x = I x
data (f :+: g) x = L (f x)
| R (g x)
data (f :*: g) x = f x :&: g x
instance Differentiable (K a) where
type D (K a) = K Void
instance Differentiable I where
type D I = K ()
instance (Differentiable f, Differentiable g) => Differentiable …Run Code Online (Sandbox Code Playgroud) haskell ×1