Hacker News new | ask | show | jobs
by codnee 3280 days ago
You have a small syntax error on your third example, it should be

  var DefaultPi float64 = 3.141592
5 comments

Not to mention that there aren't enough digits there to fill the precision of a 64-bit float.
I was so confused with `type DefaultPi float64 = 3.141592`... I thought Go had started supporting defining custom default values for types and then interpreting `type` as its default value when used in expressions....
The funny thing is that there are languages that allow constants into the type system. The feature has a few names, but one of them is pi-types (well, π-types) [1]. Go even uses them for its array types. However like generics, it's not a feature of the type system that can be used outside the built-in types.

[1] https://en.wikipedia.org/wiki/Dependent_type#Formal_definiti...

Thank you! I'll update it as soon as I can.
If you're updating it anyway, perhaps consider not using Pi as a config value in the first place.
how about `const DefaultPi = 3.14159265`