Min/Max overloads, and type promotion

Monkey Forums/Monkey Programming/Min/Max overloads, and type promotion

Nobuyuki(Posted 2012) [#1]
Why doesn't the function Min(x:Int, y:Float) or Min(x:Float, y:Int) exist? Does this have to do with the typing philosophy of Monkey? I'm having trouble understanding why we can't mix Ints and Floats with these functions.


Also, while I'm on the subject of type promotion, what's the deal with types being evaluated on the parenthesis scope instead of on a line scope? Is that normal for most languages? (I honestly don't know.) For example:

[monkeycode]
A:Int
B:Int

'Perhaps not expected behavior
C:Float = Cos(A/B) * 42 '(A/B) will always return an Int

'Expected behavior
C:Float = Cos(float(A)/float(B)) * 42 '42.0 won't promote the entire expression, since the line is eval'd by blocks(?)

[/monkeycode]


ziggy(Posted 2012) [#2]
In your example, Cos is a function. Monkey does evaluate the parameter, wich si a fair simple operation A/B, wich is an integer operation, the result is integer. It has non sense to have explicit conversions unless you want to make your code very harder to maintaint as you'll be guessing all the time what the compiler "should be doing". There's a nice explanation about type balancing on the Monkey documentation wiki.