I'ld like to implement a general Gaussian function for scalars and vectors. In Ada or C++ I simply would choose template for this, but in Haskell it's a little bit confusing.
I would start by defining a class that can apply Gaussian operators, like combining or calculating the probability:
class Gaussian g where
(!*) :: g -> g -> g
prob :: g -> a -> Float -- Here, I want a to be depending on g
data Gaussian1D = Gaussian1D Float Float
data Gaussian2D = Gaussian2D (Linear.V2 Float) Linear.V2(LinearV2 Float)
, and I'ld like to have something like:
instance Gaussian Gaussian1D where
prob :: Gaussian1D -> Float -> Float
instance Gaussian Gaussian2D where
prob :: Gaussian2D -> Linear.V2 Float -> Float
But I'm not able to implement this in a nice way. Would this somehow be possible with a multiparameter class without digging into the field of template-haskell, eg:
class Gaussian g a where
(!*) :: g a -> g a -> g a
prob :: g a -> a -> Float
? At the moment, I'm failing to realize this scenario when I do domething like:
data Gaussian1D = Gaussian1D Float Float
instance Gaussian Gaussian1D Float where
with error:
Expected kind ‘* -> *’, but ‘Gaussian1D’ has kind ‘*’ (btw, I don't understand why this error occurs)
Thx