Somehow, I'm still trying to build an intuition on what can I express in Haskell and what not.
I have my own (simple) matrix type and I'm wondering if it would be possible to somehow "lift" it to a function so as to make sense of the usual math notation for a matrix applied on a vector.
Let me explain this question in more detail.
data Matrix a = M [[a]] deriving (Show,...)
dot u v = foldr (+) 0 $ zipWith (*) u v
mv :: Num a => Matrix a -> [a] -> [a]
mv (M []) _ = []
mv _ [] = []
mv (M m) v = dot (head m) v : mv (M (tail m)) v
Clearly, the function mv
implements the action of a matrix M m
on a "vector" of type [a]
.
But, is there a way to implement the same action with a syntax like (M' m) v
such that
(M' m) v = mv (M m ) v ?
It should then allow to write something like
m = M' [[2,3],[5,7]]
v = m [1,0] -- v == [2,5]
I suspect the matrix data type I defined isn't enough to do such a lifting. Somehow I think I'm trying to find a functor from a self-defined matrix type to some hom([a],[a])
, i.e., the set of morphisms in category of vector spaces Vec
, but my data type lacks the necessary structure.
Is there a fundamental reason why it might not be possible to do such "lifting"?