Add -fextended-default-rules and -fmono-pat-binds
authorsimonpj@microsoft.com <unknown>
Mon, 7 Aug 2006 11:21:07 +0000 (11:21 +0000)
committersimonpj@microsoft.com <unknown>
Mon, 7 Aug 2006 11:21:07 +0000 (11:21 +0000)
commit6e0c3f50e131f502577a61b09a339af295de9d23
tree064e40d1ed17b3fa4d783fec2369fd199e6a1098
parent25adfa02ca196b3792cfb8a5ec7d6eca941e8986
Add -fextended-default-rules and -fmono-pat-binds

Add -fextended-deafult-rules (in response to Don Stewart's message below),
and document them.

Also doucument -fmono-pat-binds/-fno-mono-pat-binds, which has been in
GHC a few weeks now.

(The two are in one patch because the diffs were so close together
that Darcs combined them.)

Simon

From: Donald Bruce Stewart [mailto:dons@cse.unsw.edu.au]
Sent: 07 August 2006 10:52

While we're thinking about defaulting, I have a question..

ghci uses an extended defaulting system, to allow things like:
        Prelude> reverse []
        []
to work, and to have the right instance of Show found. The manual says:

    "..it is tiresome for the user to have to specify the type, so GHCi extends
    Haskell's type-defaulting rules (Section 4.3.4 of the Haskell 98 Report
    (Revised)) as follows. If the expression yields a set of type constraints
    that are all from standard classes (Num, Eq etc.), and at least one is
    either a numeric class or the Show, Eq, or Ord class, GHCi will try to use
    one of the default types, just as described in the Report. The standard
    defaulting rules require that one of the classes is numeric; the difference
    here is that defaulting is also triggered at least one is Show, Eq, or Ord."

Currently, there is no way to get at this "extended" defaulting for compiled
modules. However, I have a use case for in fact doing this.

With runtime evaluated Haskell, embedding 'interpreters' (over hs-plugins) is
easy. lambdabot, for example, implements a sandboxed haskell eval system. But
it doesn't have access to the defaulting mechanism of ghci, so we have:

    dons:: > reverse []
    lambdabot:: Add a type signature
    dons:: > reverse [] :: [()]
    lambdabot:: []

Which is annoying -- newbies wonder why they have to add these extra
constraints to get a Show instance.

I'm wondering, since the extended defaulting mechanisms are already
implemented, could they be made available to compiled modules as well,
perhaps using a flag, -fextended-defaulting?
compiler/main/DynFlags.hs
compiler/typecheck/TcSimplify.lhs
docs/users_guide/flags.xml
docs/users_guide/ghci.xml
docs/users_guide/glasgow_exts.xml