I already asked a similar question but it was not clear enough, so I decided to rephrase it.
I know that a matrix is an applicative functor
but not a monad. I am wondering if there is a simple and practical example of <*>
for matrices.
I already asked a similar question but it was not clear enough, so I decided to rephrase it.
I know that a matrix is an applicative functor
but not a monad. I am wondering if there is a simple and practical example of <*>
for matrices.
A possible Applicative
instance for matrices would be to make it analogous to ZipList. With F
a matrix of functions, and X
a matrix of values, F <*> X
applies each function in F
pointwise to each value in X
. The result is truncated in each dimension to fit the shortest matrix. pure f
gives an infinite matrix with f
at each point. As an example example, the pointwise matrix multiplication is then (*) <$> A <*> B
.
In stead of truncation and working with infinity, you could fix the shape of the matrix by using a phantom type parameter as used in accelerate
. Of course, then you could also declare a Monad instance just like with fixed size ziplists.