That is fine if you find it easier to read. The generated code will
most likely be the same. Note that you probably want int64 rather
than int.
> PS "invalid operation" isn't a syntax error, at least in the way I thinkAgreed, but I think it was you who said it was a syntax error. The
> of syntax errors: `maxOutstanding * runTime` is a perfectly
> syntactic expression that happens, by virtue of certain properties
> of the identifiers in it, to be disallowed.
compiler only said it was an invalid operation, which it is.
...
- So what's the solution? Casting? I think I can work that out.
- The compiler message included the phrase 'mismatched types', which sounds like a syntax error to me. Conceptually, I disagree: I think it should be allowed.
- We can imagine a physics package that allows for time-squared to allow coding, as an example, Galileo's Law of Fall, which involves the square of an elapsed time (the square of a Duration).
- The time package has an Add(), I guess I could put that in a loop, add the appropriate number of Durations to a Time, and then subtract out the original Time. It hurts even to think about this.
It depends on whether the integer is const or not.This program works as expected:package mainimport ("fmt"; "time"; "reflect")func main () {const m = 10fmt.Printf("TypeOf(m) is %s\n", reflect.TypeOf(m).Name())waiter := time.Duration(3600000000)bigwait := m * waiterfmt.Printf("waiter is %v, bigwait %v\n", waiter, bigwait)}The output is:TypeOf(m) is intwaiter is 3.6s, bigwait 36sBut change the 'const m' to a 'var m' and the old error message returns:invalid operation: m * waiter (mismatched types int and time.Duration)NOTE: The const is an int according to reflection, and the var is an int according to the error message, so the problem isn't about the type being 'int', it's about it not being 'const'. The type rules of the language are inconsistent. At the very least the reflect package should describe the const as 'const int' since it actually make a difference.
It depends on whether the integer is const or not.This program works as expected:package mainimport ("fmt"; "time"; "reflect")func main () {const m = 10fmt.Printf("TypeOf(m) is %s\n", reflect.TypeOf(m).Name())waiter := time.Duration(3600000000)bigwait := m * waiterfmt.Printf("waiter is %v, bigwait %v\n", waiter, bigwait)}The output is:TypeOf(m) is intwaiter is 3.6s, bigwait 36sBut change the 'const m' to a 'var m' and the old error message returns:invalid operation: m * waiter (mismatched types int and time.Duration)NOTE: The const is an int according to reflection, and the var is an int according to the error message, so the problem isn't about the type being 'int', it's about it not being 'const'. The type rules of the language are inconsistent. At the very least the reflect package should describe the const as 'const int' since it actually make a difference.
Also, there is no way to convert or cast a variable to a const, so that path is blocked.
This also means there is nothing sensible for me to convert my variable integer to that would allow me to multiply.
But, if I convert/cast the variable integer to a time.Duration(), I can multiply the durations together to get the sensible duration. Problem solved at the cost of some time. That is, time squared...RickyS
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
If Jeremy Wall is right, and it seems to me he is, then TypeOf (and reflection) should be in the language and not a package.
On Wednesday, June 19, 2013 10:52:08 PM UTC+3, Jeremy Wall wrote:Since we are dealing in technicalities here the m is not an int. It's a numeric constant. It gets cast to an int when you pass it to the TypeOf function.
...
What you say is consistent, as the error message (mismatched types) re-appears when m is declared as:const m int = 100
But: This means the internal representation of a Duration (or any type) is not truly encapsulated. If a Duration were typed as a struct that contained an int64 then multiplication by a constant would not work, either. This breaks my expectations, but my expectations were created by using other languages.This also means that defining Duration as:type Duration int64creates Duration as an alias of int64, which the language docs deny.
What you say is consistent, as the error message (mismatched types) re-appears when m is declared as:const m int = 100
But: This means the internal representation of a Duration (or any type) is not truly encapsulated. If a Duration were typed as a struct that contained an int64 then multiplication by a constant would not work, either. This breaks my expectations, but my expectations were created by using other languages.This also means that defining Duration as:type Duration int64creates Duration as an alias of int64, which the language docs deny.