True being coercible to a number is unfortunate, but it's still not the same as what C does with that printf.
"foo" * 3 is just an example of a polymorphic operator. You could implement the same in any strongly typed language that allows polymorphic operators.
If you tried it with variables you would get a type error:
> let x = 1.0 :: Double
> let y = 1 :: Int
x + y
<interactive>:10:5:
Couldn't match expected type ‘Double’ with actual type ‘Int’
In the second argument of ‘(+)’, namely ‘y’
In the expression: x + y
It sometimes looks like conversion because the literal `1` is polymorphic and can have a more specific type like `Int` or `Double` inferred from context. λ> :t 5
5 :: Num a => a
λ> :t 5.6
5.6 :: Fractional a => a
λ> :t (5 :: Integer)
(5 :: Integer) :: Integer
The type of the literal "Num a => a" means that the literal "5" works for any type in the Num typeclass. So you can mix literals with any numeric type because the compiler will correctly infer the right type. You can even get usages like this: λ> :t (\x -> x + 5)
(\x -> x + 5) :: Num a => a -> a
λ> let f = (\x -> x + 5) in (f (0 :: Int), f (0 :: Double))
(5,5.0)If we want to be really pedantic, in Python 2.X, True isn't coercible to an integer, it is an integer.
>>> True == 1 True >>> isinstance(True, int) True
This is an artifact of the fact that when Python was first created, it didn't have boolean types, so when they were added later, "True" and "False" were bolted on as aliases to the integers 1 and 0.
Yeah I kinda forgot about the result.
> Python doesn't even have a printf function, where did you get the idea it was supposed to be Python?
Nowhere? I never assumed your example was python, I was showing something irrelevant.
If that's not what you mean, that was not at all evident.
It's not, I pretty much fell into the issue you decry at the end of your comment: I considered the operation being allowed at all (by the compiler and the runtime) not being evidence of weak typing. Which I guess is technically correct, but is mostly completely irrelevant to the point you were making.
> printf("%d", 42.0);
which does not demonstrate your point and is valid Python:
also the more odd and who could forget edit: forget about this, for some reason I'd forgotten what the example would output…