mstksg / backprop

Heterogeneous automatic differentiation ("backpropagation") in Haskell
https://backprop.jle.im
BSD 3-Clause "New" or "Revised" License
181 stars 22 forks source link

Why not have an undecidable instance Num a => Backprop a ? #6

Closed stites closed 6 years ago

stites commented 6 years ago

which would be satisfied with the *Num functions?

mstksg commented 6 years ago

This would make all instances ever for Backprop be overlapping instances, even for types that don't have Num instances, which is a bit too dangerous/playing with fire -- definitely not something that the haskell type system was designed to handle, heh.

An alternative nice solution would probably leverage DerivingVia when that extension lands (ghc-proposals/ghc-proposals#120) to allow deriving with Num or Generics.

mstksg commented 6 years ago

It also precludes the possibility of a type implementing its own instance of Backprop if it has a Num instance, even if there is a potentially faster implementation than addNum/zeroNum/oneNum

stites commented 6 years ago

:+1: yup, makes sense!