News for hackers. Stuff that matters.
Re:Ivo – a reimagined Unix terminal system by derleth on Thursday December 01, 2011 @01:43PM (#3300889)
Weak typing and implicit coercion are not the same thing. They're not even close to the same thing. Haskell does (things equivalent to) implicit coercion when it adds a floating-point Number to an integral Number and nobody (sane) says Haskell is weakly-typed.
Re:Ivo – a reimagined Unix terminal system by rawatson on Thursday December 01, 2011 @05:13PM (#3301626)
Haskell uses type inference, but that's not the same as implicit coercion, which Haskell explicitly avoids. That is: if you type 4 + 4.2

Then the compiler will infer that you mean (4::Fractional a=>a) + (4.2::Fractional a => a)

However, you cannot add an integer and a float: (4::Int) + (4.2::Float)

    Couldn't match expected type `Int' with actual type `Float'

    In the second argument of `(+)', namely `(4.2 :: Float)'

    In the expression: (4 :: Int) + (4.2 :: Float)

    In an equation for `it': it = (4 :: Int) + (4.2 :: Float)
This follows from the type of (+) :: Num a => a -> a -> a
Re:Ivo – a reimagined Unix terminal system by derleth on Thursday December 01, 2011 @05:22PM (#3301657)
I guess I still don't get how there could be a difference between Float and Fractional, then.
Re:Ivo – a reimagined Unix terminal system by rawatson on Thursday December 01, 2011 @05:34PM (#3301709)
Haskell uses type classes to support ad hoc polymorphism, or overloading. Consider the statement:

(4.2::Fractional a=> a) + (4::Float)

Float is an instance of the type class Fractional. That is: methods which are defined for all fractional types must be defined for floats.

The compiler infers that (4.2::Fractional a=>a) must have type float, as it is being added to a float. This is compatible with the original type of the expression, as Float is an instance of fractional, so it is valid to read 4.2 as a Float.

This diagram might help: http://www.haskell.org/onlinereport/basic.html#sect6.3