Hacker News new | ask | show | jobs
by phoe-krk 1892 days ago
> (...) that has the nasty problem that 3 does not have a type (...)

How is that possible? At least in Common Lisp, all literal objects have types, and the same is true of C from what I have just checked.

2 comments

Go supports untyped constants -- https://golang.org/ref/spec#Constants. It's useful for defining a named constant, and then using the name to initialize variable values of any compatible type.
It doesn't have a type in Haskell, from a certain point of view. `3` is polymorphic.

Prelude> :t 3

3 :: Num p => p

It does have a type. You just wrote it down!
Hence "from a certain point of view" - I would argue, in fact, that it's extremely similar to the sense in which 3 doesn't have a type in Go. Haskell's type system can express that sense, whereas Go's can't; but it's the same sense.

> It is an error if the constant value cannot be represented as a value of the respective type. An untyped constant has a default type which is the type to which the constant is implicitly converted in contexts where a typed value is required, for instance, in a short variable declaration such as i := 0 where there is no explicit type. The default type of an untyped constant is bool, rune, int, float64, complex128 or string respectively, depending on whether it is a boolean, rune, integer, floating-point, complex, or string constant.