backprop
backprop copied to clipboard
Fix compilation error on GHC-9.0 due to simplified subsumption
GHC-9.0 failed to type-check the current implementation of withVec
https://github.com/mstksg/backprop/blob/e8962c2029476c7721c5f5488e8689737294ceee/src/Data/Type/Util.hs#L70-L76
with the following error:
[ 1 of 10] Compiling Data.Type.Util
/.../backprop/src/Data/Type/Util.hs:75:14: error:
• Couldn't match type: VecT 'Z f0 a0 -> r
with: forall (n :: Nat). VecT n f a -> r
Expected: (forall (n :: Nat). VecT n f a -> r) -> r
Actual: (VecT 'Z f0 a0 -> r) -> r
• In the expression: $ VNil
In a case alternative: [] -> ($ VNil)
In the expression:
\case
[] -> ($ VNil)
x : xs -> \ f -> withVec xs (f . (x :*))
• Relevant bindings include
withVec :: [f a] -> (forall (n :: Nat). VecT n f a -> r) -> r
(bound at src/Data/Type/Util.hs:74:1)
|
75 | [] -> ($ VNil)
| ^^^^^^
Before GHC 9.0, ($ VNil)
's type (VecT 'Z f0 a0 -> r) -> r
is considered more polymorphic than expected type (forall (n :: Nat). VecT n f a -> r) -> r
because of the contravariance of functions types in the subsumption judgement.
But the simplify subsumption proposal landed on GHC 9.0 removed the contravariance, and caused the type error.
This PR fixes the problem by simple eta-expansion.
Indeed, I experience the same with GHC 9.2.1.
And the fix indeed works for me on GHC 9.2.1, but the following failed:
[ 2 of 10] Compiling Numeric.Backprop.Class ( src/Numeric/Backprop/Class.hs, /home/mikolaj/r/mostly-harmless/dist-newstyle/build/x86_64-linux/ghc-9.2.1/backprop-0.2.6.4/build/Numeric/Backprop/Class.o, /home/mikolaj/r/mostly-harmless/dist-newstyle/build/x86_64-linux/ghc-9.2.1/backprop-0.2.6.4/build/Numeric/Backprop/Class.dyn_o )
src/Numeric/Backprop/Class.hs:905:34: error: Not in scope: type constructor or class ‘SG.Option’ Module ‘Data.Semigroup’ does not export ‘Option’. | 905 | instance Backprop a => Backprop (SG.Option a) where | ^^^^^^^^^
@mstksg friendly ping
@mstksg can we merge this?
thanks for this, sorry for the delay!