X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=0c3b07cb6c50d9e3bda756061f9b75083a8cc85a;hb=f94f26a7cb7bb7005b88f50c4383a761fc18718d;hp=29e708205918b5516049e228d9a89e965c3a4802;hpb=3de26aa3d728b06ee7bf658fec6a09855822d492;p=ghc-hetmet.git
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 29e7082..0c3b07c 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -241,6 +241,14 @@ documentation describes all the libraries that come with GHC.
+
+
+ Enables overloaded string literals (see ).
+
+
+
+ Enables lexically-scoped type variables (see
-clunky env var1 var1 = case lookup env var1 of
+clunky env var1 var2 = case lookup env var1 of
Nothing -> fail
Just val1 -> case lookup env var2 of
Nothing -> fail
@@ -645,7 +653,7 @@ Here is how I would write clunky:
-clunky env var1 var1
+clunky env var1 var2
| Just val1 <- lookup env var1
, Just val2 <- lookup env var2
= val1 + val2
@@ -2069,7 +2077,7 @@ the standard method is used or the one described here.)
Stand-alone deriving declarations
-GHC now allows stand-alone deriving declarations:
+GHC now allows stand-alone deriving declarations, enabled by -fglasgow-exts:
data Foo a = Bar a | Baz String
@@ -4056,6 +4064,57 @@ pattern binding must have the same context. For example, this is fine:
+
+Overloaded string literals
+
+
+
+GHC supports overloaded string literals. Normally a
+string literal has type String, but with overloaded string
+literals enabled (with -foverloaded-strings)
+ a string literal has type (IsString a) => a.
+
+
+This means that the usual string syntax can be used, e.g., for packed strings
+and other variations of string like types. String literals behave very much
+like integer literals, i.e., they can be used in both expressions and patterns.
+If used in a pattern the literal with be replaced by an equality test, in the same
+way as an integer literal is.
+
+
+The class IsString is defined as:
+
+class IsString a where
+ fromString :: String -> a
+
+And the only predefined instance is the obvious one to make strings work as usual:
+
+instance IsString [Char] where
+ fromString cs = cs
+
+
+
+A small example:
+
+newtype MyString = MyString String deriving (Eq, Show)
+instance IsString MyString where
+ fromString = MyString
+
+greet :: MyString -> MyString
+greet "hello" = "world"
+greet other = other
+
+main = do
+ print $ greet "hello"
+ print $ greet "fool"
+
+
+
+Note that deriving Eq is necessary for the pattern matching
+to work since it gets translated into an equality comparison.
+
+
+
@@ -5899,12 +5958,6 @@ The following are good consumers:
- length
-
-
-
-
-++ (on its first argument)