The Haskell 98 report, section 4.3.4 states:

   [...] In situations where an ambiguous type is discovered, an
   ambiguous type variable is defaultable if at least one of its
   classes is a numeric class (that is, Num or a subclass of Num)
   and if all of its classes are defined in the Prelude or a
   standard library [...]

What is the rationale for the second condition, i.e. why is no
defaulting done when a user-defined class is involved? Example:

   default (Float)

   class Num a => Bar a where bar :: a -> String

   instance Bar Float  where bar = const "Float"
   instance Bar Double where bar = const "Double"

   main :: IO ()
   main = putStrLn (bar 123.456)

This does not work, because the type of 123.456 must be an instance of
Fractional (no problem) and Bar (problem!). More convincing, but longer
examples can be constructed for geometric things like vectors, matrices,
etc. which contain elements of a polymorphic numeric type.

When no good reason for this restriction exists, it should be removed
IMHO. This only extends the set of programs which can be compiled, and
existing programs don't change their meaning.

Cheers,
   Sven
-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne

Reply via email to