diff options
author | simonpj@microsoft.com <unknown> | 2007-02-21 10:36:45 +0000 |
---|---|---|
committer | simonpj@microsoft.com <unknown> | 2007-02-21 10:36:45 +0000 |
commit | 041c35e5d9f3aefab6908b4c776a3fd8242720ab (patch) | |
tree | 70ecd3823e2a46e2e9c34e93cfd91cc16109818c /docs | |
parent | b2b9ba4a8872f1dcc69e2801fb42c2543bf36b52 (diff) | |
download | haskell-041c35e5d9f3aefab6908b4c776a3fd8242720ab.tar.gz |
Fix defaulting for overloaded strings
This patch fixes the typechecking of the default declaration itself,
when overloaded strings are involved. It also documents the behaviour
in the user manual.
nofib/spectral/power should work again now!
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index dfedb083b5..a8c91dff8f 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -4086,15 +4086,39 @@ The class <literal>IsString</literal> is defined as: class IsString a where fromString :: String -> a </programlisting> -And the only predefined instance is the obvious one to make strings work as usual: +The only predefined instance is the obvious one to make strings work as usual: <programlisting> instance IsString [Char] where fromString cs = cs </programlisting> +The class <literal>IsString</literal> is not in scope by default. If you want to mention +it explicitly (for exmaple, to give an instance declaration for it), you can import it +from module <literal>GHC.Exts</literal>. +</para> +<para> +Haskell's defaulting mechanism is extended to cover string literals, when <option>-foverloaded-strings</option> is specified. +Specifically: +<itemizedlist> +<listitem><para> +Each type in a default declaration must be an +instance of <literal>Num</literal> <emphasis>or</emphasis> of <literal>IsString</literal>. +</para></listitem> + +<listitem><para> +The standard defaulting rule (<ulink url="http://haskell.org/onlinereport/decls.html#sect4.3.4">Haskell Report, Section 4.3.4</ulink>) +is extended thus: defaulting applies when all the unresolved constraints involve standard classes +<emphasis>or</emphasis> <literal>IsString</literal>; and at least one is a numeric class +<emphasis>or</emphasis> <literal>IsString</literal>. +</para></listitem> +</itemizedlist> </para> <para> A small example: <programlisting> +module Main where + +import GHC.Exts( IsString(..) ) + newtype MyString = MyString String deriving (Eq, Show) instance IsString MyString where fromString = MyString |