I defined :
type Network = [(Matrix Double,Vector Double)]
where Matrix and Vector are from the hmatrix library. From the documentation of hmatrix it seems to me that Matrix Double and Vector Double are already instances of Num. Since I need to add and subtract Networks quiet a lot I also want Network to be an instance of Num. I tried
instance Num Network where
(+) = zipWith (\(m,v) (n,w) -> (m+n,v+w))
(-) = zipWith (\(m,v) (n,w) -> (m-n,v-w))
(*) = zipWith (\(m,v) (n,w) -> (m*n,v*w))
but I am getting the error : Illegal Instance declaration.
FlexibleInstances
language extension to create instances over type synonyms like the one you’ve written. The GHC error message might even suggest this (along withTypeSynonymInstaces
, thoughFlexibleInstnaces
implies the former). – Alexis KingVectorSpace
instance, though, but you should definitely wrap it in anewtype
. – leftaroundaboutsignum
andabs
. Failing to do so may cause your programs to crash because some piece of code actually uses these and they end upundefined
. – Bakuriu