In the random-fu package, there is this data declaration:
data Multinomial p a where
Multinomial :: [p] -> a -> Multinomial p [a]
I understand that this is a GADT, but what is it trying to accomplish? Is it placing restrictions on p or a, etc?
It changes the return type of the constructor. If it was defined like this
data Multinomial p a = Multinomial [p] a
our constructor would have the type
Multinomial :: [p] -> a -> Multinomial p a
The GADT changes the second type argument in the result type of the constructor to [a].
As for the "why", the Distribution type-class defines rvar as
class Distribution d t where
rvar :: d t -> RVar t
So the type parameter of the given distribution determines the type of the samples you get out of the RVar. So using the GADT, the Multinomial distribution is defined as one that always returns multiple values per sample even though it's constructed with just a single value of a.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With