I have a matrix representation of
data ListN (dim :: Nat) a where
Nil :: ListN Zero a
Cons :: a -> ListN n a -> ListN (Succ n) a
infixr 5 `Cons`
data Tensor (dims :: [Nat]) a where
Dense :: (Product dims ~ n) => ListN n a -> Tensor dims a
Sparse :: Tensor n a
where Product
makes sure dims
is equal with n
when you take the product of all the elements of dims
.
Now I would like to have a creator function and a function that changes the dimensions of the tensor data type.
- I would like to have one function that changes the dimensions of the matrix, but only if the product of a given
[Nat]
is equal to thedims
of the matrix that has to be changed. I already thought of something like:reshape :: (Product lm ~ l, Product (ns :: [Nat]) ~ n, l ~ n ) => Tensor ns a -> lm -> Tensor lm a
. But that doesn't type check. - I would also like to have a function that can create a Tensor when given a
[Nat]
but once again that list should have a product that is the same as the amount of elements of a givenListN n a
. I thought offromList :: (Product lm ~ l, Product (ns :: [Nat]) ~ n, l ~ n ) => ListN n a -> lm -> Tensor lm a
. But that also doesn't type check.