I was converting one of my projects to elm 0.19 and encountered such case:
In 0.18 we had Color module with rgb function, so in code it looked something like that:
Color.rgb 128 128 128
I’m using style-elements package and I had to replace Color.rgb with Style.rgb. The last has the following signature:
rgb : Float -> Float -> Float -> Color
Where each parameter has a range from 0.0 to 1.0. Naturally, all elements became white
Fortunately, in this particular case it was easy noticeable, but I wonder if such casting could be a reason for hard to spot bugs.
So the literal 128 is not an Int but rather a number. This is a special type that says “I haven’t decided yet if I want this to be an integer or a float”.
If it gets used in a function that requires integers then the compiler decides it is going to be an integer. If it gets used in a function that requires floats then the compiler will decide it’s a float. And if it gets used in a function that allows either then the compiler will let it stay as a number.
Interesting, I had never really got my head around how this works. Sometimes I might have an expression like
((start + offset) + (end + 10)) / 2
Where start : Float and end : Float but offset : Int. The compiler would then tell me that I need to convert offset explicitly to Float but would take the 10 and the 2 quite happily. I fixed the error but was always left a bit puzzled, but I see how it works now with the number type.