Given the type, there is only one obvious way to implement an Additive instance, from the Linear library, to it. Conveniently, Additive has a common implementation, so we can use deriving for it. Unfortunately, this depends on the existence of an Applicative instance that is not output, so you should still declare it:
{-# LANGUAGE DeriveGeneric, DeriveFunctor #-} import Linear import GHC.Generics import Control.Applicative data Foo a = Foo aaa deriving (Show, Functor, Generic1) instance Additive Foo instance Applicative Foo where pure x = Foo xxx Foo fgh <*> Foo xyz = Foo (fx) (gy) (hz) main = print $ Foo 1 2 3 ^+^ Foo 4 5 6
Is there a way to get Additive automatically without declaring an applicative instance?
source share