patch applied (ghc): Add -fextended-default-rules and -fmono-pat-binds

Simon Peyton Jones simonpj at microsoft.com
Mon Aug 7 11:29:17 EDT 2006


Mon Aug  7 04:21:07 PDT 2006  simonpj at microsoft.com
  * 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 at 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? 
  

    M ./compiler/main/DynFlags.hs -2 +4
    M ./compiler/typecheck/TcSimplify.lhs -8 +11
    M ./docs/users_guide/flags.xml -1 +13
    M ./docs/users_guide/ghci.xml -1 +3
    M ./docs/users_guide/glasgow_exts.xml +39


More information about the Cvs-ghc mailing list