Just wondering type system of go (would like to understand more). For example, passing integer value to float type just works. What is the intent of such kind of flexibility?
Basically when you pass a value into a function that takes a float, if the type hasn't been explicitly resolved, it will coerce it into a float (if it can, it wouldnt do it on a string).
So when you say "why can you pass integers", well you're not really. It's just 2 is being turned into a float.
Thank you so much for this tutorial.
Just wondering type system of go (would like to understand more). For example, passing
integer
value tofloat
type just works. What is the intent of such kind of flexibility?Glad it's helpful!
I hope this will help: play.golang.org/p/gTXh3vhOj-z
Basically when you pass a value into a function that takes a float, if the type hasn't been explicitly resolved, it will coerce it into a float (if it can, it wouldnt do it on a string).
So when you say "why can you pass integers", well you're not really. It's just 2 is being turned into a float.
Does that make sense?
Thanks Chris. Yes that makes sense.