> Have you spent any time at all using them?
Sure I have used both.
Default arguments and implicits both have the same key idea: you can
omit arguments to functions, and the compiler, guided by type
information, synthesises the missing arguments during compilation. In
order to understand the difference between both, it is crucial to
realise that this compile-time synthesis of missing arguments has two
related but different dimensions.
- Declaration that an argument is allowed to be omitted (and hence
synthesised automatically).
- Declaration of the missing argument that is used in this synthesis.
Default arguments merge these two into one, e.g. with
def f ( int x ) ( bool b = false ) = ...
f (2)
f (2)
all calls f(2) become f(2)(false). The problem with this is that the
devault value to be used in synthesis cannot be context dependent.
Implicit arguments separate these two, enabling the programmer to
make default context dependent, e. g.
def f ( int x ) ( implicit bool b ) = ...
implicit val c = true
f (2)
implicit val c = false
f (2)
Now the first call f(2)
is rewritten to f(2)(true), while the second becomes f(2)(false).
> Would you claim that HKT isn't anything new or novel because constructors have been around forever?
I'm not sure I see the connection: constructors are program constructs, while HKTs are "types for types".