Re:Tulip – An untyped functional language
by iopq on Saturday March 28, 2015 @12:16AM
(#9280493)
you can easily add a number to a char in C and get a jibberish character, which is why C is a weakly typed language
[ Parent
| on HN ]
Not true (technically). When you add an integer to a char, you get an integer. (If you add a floating point number, the result is such as well.)
You can, of course, use the integer you got like a char (after all, C's char is a small integer type) to get your gibberish. You can also use a floating point number as a char, because C has lax implicit conversions.
If you add '!' to '#' you get 'D', which is non-sense in any high level language.
Not true; you added the byte that happens to be identified in ASCII by !, 33, to the byte that happens to be identified in ASCII by #, 35, and get 68, which is D. This is all perfectly sensible and type safe, two 8-bit numbers being added to produce another 8-bit number; you are only confused by the surface syntax. There's plenty of high-level languages that will let you do this; there's all sorts of reasons to make numbers and the ASCII chars they represent easily usable for each other in source code.
No, I didn't. I actually added the character '!' to '#'. The C language doesn't DISTINGUISH characters from their numerical representations. That's where I say it's weakly typed. It does not have an actual character type, it only has 8 bit numbers.
Of course in C it is perfectly logical. I am pointing out that it is not as strongly typed as other type systems that have richer types.