Hi, pardon me if I'm not using quite the right terminology
.
I'll give you a practical problem I had in a C program (and I could have 
had it in Jula, it seems) :
I was dealing with image processing, and as you know sometimes pixels are 
referenced by (row,col) but sometimes by (col,row), that is (X,Y). 
If you mix the two orders up you get havoc, of course. It just happened to 
me.
So it would be nice to have a little protection through the use of 
"aliases" which I might call "lightweight types".
The idea is that you could have  lightweight types "row_type" and 
"col_type" which are   sort of aliases for an int32 for example, except 
that you cannot pass a row_type argument to a function that
is expecting a col_type, unless you do an explicit conversion.
However you *are* allowed to multiply a variable of type row_type with one 
of col_type (and the result type is an int32) without having to  define an 
operator (as you would if you tried to do this via classes in C++).
And you are allowed to define initialisation of a row_type variable to a 
litteral or an int, without any special instruction.
In C the typedef mechanism does not provide this kind of protection it 
seems.

I hope that this kind of lightweight mechanism (in Julia)might avoid a lot 
of errors, with little effort on the part of the programmer.
Thanks for reading


Reply via email to