
Thanks Yury,
The problem with this solution is that if I have written a method for the
Tensor type (for example a method of a typeclass of which Tensor is an
instance) that uses the order of the tensor (your "ndims") in a general way, I
cannot reuse it easily for a vector defined like that.
In fact, my problem is to be able to define:
* from my type "Tensor", a type "Vector", by specifying that the dimension
must be one to have a "Vector" type.
* from my constructor "TensorVar", a constructor "VectorVar", which
corresponds to TensorVar with the integer equal to 1.
The idea is to avoid duplicating code, by reusing the tensor type and data
constructor. At some place in my code, in some definition (say, of a vector
product), I want vectors and not more general tensors.
TP
On Saturday, April 27, 2013 16:16:49 Yury Sulsky wrote:
Hi TP,
Are you looking to use a phantom types here? Here's an example:
data One
data Two
data Tensor ndims a = Tensor { dims :: [Int], items :: [a] }
type Vector = Tensor One
type Matrix = Tensor Two
etc.
On Sat, Apr 27, 2013 at 3:33 PM, TP