It's basically Hindley-Milner.

kdevel kdevel at vogtner.de
Fri Mar 24 12:29:02 UTC 2023


On Friday, 24 March 2023 at 09:47:59 UTC, FeepingCreature wrote:
> On Friday, 24 March 2023 at 09:44:28 UTC, FeepingCreature wrote:
>> If we insert the missing step, what the compiler should do is: 
>> "Ah, `B` is a 'trivial alias'
>
> My apologies, correction: `A` is a 'trivial alias'. Sorry for 
> the minipost, but this topic demands precision.

Thanks for explaining what goes on under the hood. I would like 
to branch to something entirely different, namely the original 
code Elfstone drafted in the first post:

```
struct Matrix(S, size_t M, size_t N)
{
}

alias Vec3(S) = Matrix!(S, 3, 1);
```

What is conceptually wrong with this code? Can't we read 
everywhere [1] that matrices with only one column ‘are’ (column) 
vectors?

However, a matrix is a two-dimensional aggregate, its elements 
are refered to with two indices. By contrast vectors are 
one-dimensional. Of course it is elegant to define the dot 
product of a (row) vector and a (column) vector in terms of 
matrix multiplication [2] but the interesting part  here is the 
the ‘identification’ of the result (dot product) with the element 
(1, 1) of the resulting 1×1 matrix. Sometimes this precision gets 
lost, e.g. [3].

Hence: A vector should not be defined as a matrix with only 
column (or row).

[1] 
https://www.google.de/search?q=vectors+are+matrices+with+one+column
[2] https://en.wikipedia.org/wiki/Dot_product
[3] 
https://yutsumura.com/a-relation-between-the-dot-product-and-the-trace/
- "Recall that v^Tw is, by definition, the dot product of the 
vectors v and w."


More information about the Digitalmars-d mailing list