I'm not really sure what I'm doing wrong here:
data Vector2D u = Vector2D {
_x :: u,
_y :: u
} deriving stock (Show, Eq, Functor, Foldable, Traversable)
{-# INLINE addVector2 #-}
addVector2 :: (Additive a) => Vector2D a -> Vector2D a -> Vector2D a
addVector2 (Vector2D { _x = x1, _y = y1 }) (Vector2D { _x = x2, _y = y2 }) =
Vector2D { _x = x1 + x2, _y = y1 + y2 }
instance (Additive a) => Additive (Vector2D a) where
(+) = addVector2
newtype Square a = Square {
unpackSquare :: Vector2D a
} deriving stock (Show, Eq)
So far, so normal (Additive is defined in the algebra package but is pretty self-explanatory).
However, now I want to be clever using DerivingVia and StandaloneDeriving and I can't even get the next line to compile
deriving instance (Additive a) => Additive (Square a) via (Vector2D a)
But that gets me
* Expected kind `k0 -> * -> Constraint', but `Additive (Square a)' has kind `Constraint' * In the stand-alone deriving instance for `(Additive a) => Additive (Square a) via (Vector2D a)'
Can anyone tell me what I'm doing wrong? I'm running GHC 8.6.2
via ...
at the end to the one actually accepted by GHC, wherevia
comes earlier. – Crosseye