[Haskell-cafe] partially applied data constructor and corresponding type

Yury Sulsky yury.sulsky at gmail.com
Sat Apr 27 22:16:49 CEST 2013


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 <paratribulations at free.fr> wrote:

> Hello,
>
> I ask myself if there is a way to do the following.
> Imagine that I have a dummy type:
>
> data Tensor = TensorVar Int String
>
> where the integer is the order, and the string is the name of the tensor.
> I would like to make with the constructor TensorVar a type "Vector", such
> that, in "pseudo-language":
>
> data Vector = TensorVar 1 String
>
> Because a vector is a tensor of order 1.
>
> Is this possible? I have tried type synonyms and newtypes without any
> success.
>
> Thanks a lot,
>
> TP
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130427/9da661d7/attachment.htm>


More information about the Haskell-Cafe mailing list