X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=fb2124e7fb95cb5b15f708f2f2c00e0ccef276ec;hb=2c953bfaae37b427b71cbe20f0ceeda4c1d6f00f;hp=41bba186e9805d95278f5e04755f90e1ca0cf69f;hpb=1ed54200532d9a9b1b58ac914dae28c1ecb48699;p=ghc-hetmet.git
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 41bba18..fb2124e 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
@@ -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.
+
+
+
@@ -4167,6 +4226,14 @@ Tim Sheard is going to expand it.)
(It would make sense to do so, but it's hard to implement.)
+
+ Furthermore, the you can only run a function at compile time if it is imported
+ from another module that is not part of a mutually-recursive group of modules
+ that includes the module currently being compiled. For example, when compiling module A,
+ you can only run Template Haskell functions imported from B if B does not import A (directly or indirectly).
+ The reason should be clear: to run B we must compile and run A, but we are currently type-checking A.
+
+
The flag -ddump-splices shows the expansion of all top-level splices as they happen.
@@ -5899,12 +5966,6 @@ The following are good consumers:
- length
-
-
-
-
-++ (on its first argument)