[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another take on hackers and painters

John Clements writes:
> Be careful.  The distinction you're talking about is largely
> orthogonal to the dynamic vs. static typing issue.  Case in point:
> Scheme is dynamically typed, but will not perform the coercion
> you're describing. At the opposite corner, there's no reason you
> can't have a statically typed language with coercion.

Haskell does this, and the way it does so is how I learned that
automatic coercions and overloading are the same thing. Numeric
literals like 123 aren't immediately interpreted as integers. Instead,
it gets the type 'Num a => a', which says that this expression is some
kind of number, and the specific kind it gets coerced to do depends on
the context in which it is used. So writing

  let x :: Float = 3

won't cause a type error due to '3' being an integer and 'x' being a
float, like it would in ML. Haskell isn't as free-spirited with its
coercions as a language like Perl is, but that seems more a matter of
differing design sensibility rather than technical feasibility to me.

Neel Krishnaswami