| Opt_AllowIncoherentInstances
| Opt_MonomorphismRestriction
| Opt_MonoPatBinds
+ | Opt_ExtendedDefaultRules -- Use GHC's extended rules for defaulting
| Opt_GlasgowExts
| Opt_FFI
- | Opt_PArr -- syntactic support for parallel arrays
- | Opt_Arrows -- Arrow-notation syntax
+ | Opt_PArr -- Syntactic support for parallel arrays
+ | Opt_Arrows -- Arrow-notation syntax
| Opt_TH
| Opt_ImplicitParams
| Opt_Generics
( "bang-patterns", Opt_BangPatterns ),
( "monomorphism-restriction", Opt_MonomorphismRestriction ),
( "mono-pat-binds", Opt_MonoPatBinds ),
+ ( "extended-default-rules", Opt_ExtendedDefaultRules ),
( "implicit-params", Opt_ImplicitParams ),
( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
import List ( partition )
import SrcLoc ( Located(..) )
import DynFlags ( DynFlags(ctxtStkDepth),
- DynFlag( Opt_GlasgowExts, Opt_AllowUndecidableInstances, Opt_WarnTypeDefaults ) )
+ DynFlag( Opt_GlasgowExts, Opt_AllowUndecidableInstances,
+ Opt_WarnTypeDefaults, Opt_ExtendedDefaultRules ) )
\end{code}
tcSimplifySuperClasses qtvs givens sc_wanteds
= ASSERT( all isSkolemTyVar qtvs )
do { (_, frees, binds1) <- tcSimplCheck doc get_qtvs NoSCs givens sc_wanteds
- ; binds2 <- tc_simplify_top doc False NoSCs frees
+ ; ext_default <- doptM Opt_ExtendedDefaultRules
+ ; binds2 <- tc_simplify_top doc ext_default NoSCs frees
; return (binds1 `unionBags` binds2) }
where
get_qtvs = return (mkVarSet qtvs)
\begin{code}
tcSimplifyTop, tcSimplifyInteractive :: [Inst] -> TcM TcDictBinds
tcSimplifyTop wanteds
- = tc_simplify_top doc False {- Not interactive loop -} AddSCs wanteds
+ = do { ext_default <- doptM Opt_ExtendedDefaultRules
+ ; tc_simplify_top doc ext_default AddSCs wanteds }
where
doc = text "tcSimplifyTop"
-- The TcLclEnv should be valid here, solely to improve
-- error message generation for the monomorphism restriction
-tc_simplify_top doc is_interactive want_scs wanteds
+tc_simplify_top doc use_extended_defaulting want_scs wanteds
= do { lcl_env <- getLclEnv
; traceTc (text "tcSimplifyTop" <+> ppr (lclEnvElts lcl_env))
= not (bad_tyvars `intersectsVarSet` tyVarsOfInst (head ds))
&& defaultable_classes (map get_clas ds)
defaultable_classes clss
- | is_interactive = any isInteractiveClass clss
- | otherwise = all isStandardClass clss && any isNumericClass clss
+ | use_extended_defaulting = any isInteractiveClass clss
+ | otherwise = all isStandardClass clss && any isNumericClass clss
isInteractiveClass cls = isNumericClass cls
|| (classKey cls `elem` [showClassKey, eqClassKey, ordClassKey])
- -- In interactive mode, we default Show a to Show ()
- -- to avoid graututious errors on "show []"
+ -- In interactive mode, or with -fextended-default-rules,
+ -- we default Show a to Show () to avoid graututious errors on "show []"
-- Collect together all the bad guys
<entry><option>-fmonomorphism-restriction</option></entry>
</row>
<row>
+ <entry><option>-fno-mono-pat-binds</option></entry>
+ <entry>Make pattern bindings polymorphic</entry>
+ <entry>dynamic</entry>
+ <entry><option>-fmono-pat-binds</option></entry>
+ </row>
+ <row>
+ <entry><option>-fextended-default-rules</option></entry>
+ <entry>Use GHCi's extended default rules in a normal module</entry>
+ <entry>dynamic</entry>
+ <entry><option>-fno-extended-default-rules</option></entry>
+ </row>
+ <row>
<entry><option>-fscoped-type-variables</option></entry>
<entry>Enable lexically-scoped type variables.
Implied by <option>-fglasgow-exts</option>.</entry>
<sect2>
<title>Warnings</title>
- <para>(<xref linkend="options-sanity"/></para>
+ <para><xref linkend="options-sanity"/></para>
<informaltable>
<tgroup cols="4" align="left" colsep="1" rowsep="1">
</sect2>
- <sect2>
+ <sect2 id="extended-default-rules">
<title>Type defaulting in GHCi</title>
<indexterm><primary>Type default</primary></indexterm>
<indexterm><primary><literal>Show</literal> class</primary></indexterm>
numeric, <emphasis>or is <literal>Show</literal>,
<literal>Eq</literal>, or <literal>Ord</literal></emphasis>.</para></listitem>
</itemizedlist>
+ The same type-default behaviour can be enabled in an ordinary Haskell
+ module, using the flag <literal>-fextended-default-rules</literal>.
</para>
</sect2>
</sect1>
<varlistentry>
<term>
+ <option>-fno-mono-pat-binds</option>:
+ <indexterm><primary><option>-fno-mono-pat-binds</option></primary></indexterm>
+ <indexterm><primary><option>-fmono-pat-binds</option></primary></indexterm>
+ </term>
+ <listitem>
+ <para> As an experimental change, we are exploring the possibility of
+ making pattern bindings monomorphic; that is, not generalised at all.
+ A pattern binding is a binding whose LHS has no function arguments,
+ and is not a simple variable. For example:
+<programlisting>
+ f x = x -- Not a pattern binding
+ f = \x -> x -- Not a pattern binding
+ f :: Int -> Int = \x -> x -- Not a pattern binding
+
+ (g,h) = e -- A pattern binding
+ (f) = e -- A pattern binding
+ [x] = e -- A pattern binding
+</programlisting>
+Experimentally, GHC now makes pattern bindings monomorphic <emphasis>by
+default</emphasis>. Use <option>-fno-mono-pat-binds</option> to recover the
+standard behaviour.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-fextended-default-rules</option>:
+ <indexterm><primary><option>-fextended-default-rules</option></primary></indexterm>
+ </term>
+ <listitem>
+ <para> Use GHCi's extended default rules in a regular module (<xref linkend="extended-default-rules"/>).
+ Independent of the <option>-fglasgow-exts</option>
+ flag. </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<option>-fallow-overlapping-instances</option>
<indexterm><primary><option>-fallow-overlapping-instances</option></primary></indexterm>
</term>