X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=d9a6198788717b1d2299784935c4a47e0e0dfb50;hb=78b620de24ceb4621cead67bd642f72749b41052;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..d9a6198 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
@@ -956,7 +964,7 @@ a data type with no constructors. For example:
Syntactically, the declaration lacks the "= constrs" part. The
type can be parameterised over types of any kind, but if the kind is
not * then an explicit kind annotation must be used
-(see ).
+(see ).
Such data types have only one value, namely bottom.
Nevertheless, they can be useful when defining "phantom types".
@@ -1218,7 +1226,7 @@ that collection of packages in a uniform manner. You can express
quite a bit of object-oriented-like programming this way.
-
+Why existential?
@@ -1241,9 +1249,9 @@ But Haskell programmers can safely think of the ordinary
adding a new existential quantification construct.
-
+
-
+Type classes
@@ -1303,9 +1311,9 @@ Notice the way that the syntax fits smoothly with that used for
universal quantification earlier.
-
+
-
+Record Constructors
@@ -1322,7 +1330,7 @@ data Counter a = forall self. NewCounter
Here tag is a public field, with a well-typed selector
function tag :: Counter a -> a. The self
type is hidden from the outside; any attempt to apply _this,
-_inc or _output as functions will raise a
+_inc or _display as functions will raise a
compile-time error. In other words, GHC defines a record selector function
only for fields whose type does not mention the existentially-quantified variables.
(This example used an underscore in the fields for which record selectors
@@ -1368,10 +1376,10 @@ setTag obj t = obj{ tag = t }
-
+
-
+Restrictions
@@ -1522,7 +1530,7 @@ declarations. Define your own instances!
-
+
@@ -2538,7 +2546,7 @@ the context and head of the instance declaration can each consist of arbitrary
following rules:
-For each assertion in the context:
+The Paterson Conditions: for each assertion in the context
No type variable has more occurrences in the assertion than in the headThe assertion has fewer constructors and variables (taken together
@@ -2546,7 +2554,7 @@ For each assertion in the context:
-The coverage condition. For each functional dependency,
+The Coverage Condition. For each functional dependency,
tvsleft->tvsright, of the class,
every type variable in
@@ -2558,11 +2566,15 @@ corresponding type in the instance declaration.
These restrictions ensure that context reduction terminates: each reduction
step makes the problem smaller by at least one
-constructor. For example, the following would make the type checker
-loop if it wasn't excluded:
-
- instance C a => C a where ...
-
+constructor. Both the Paterson Conditions and the Coverage Condition are lifted
+if you give the
+flag ().
+You can find lots of background material about the reason for these
+restrictions in the paper
+Understanding functional dependencies via Constraint Handling Rules.
+
+
For example, these are OK:
instance C Int [a] -- Multiple parameters
@@ -2614,11 +2626,6 @@ something more specific does not:
op = ... -- Default
-You can find lots of background material about the reason for these
-restrictions in the paper
-Understanding functional dependencies via Constraint Handling Rules.
-
@@ -2683,8 +2690,8 @@ makes instance inference go into a loop, because it requires the constraint
Nevertheless, GHC allows you to experiment with more liberal rules. If you use
the experimental flag
-fallow-undecidable-instances
-option, you can use arbitrary
-types in both an instance context and instance head. Termination is ensured by having a
+option, both the Paterson Conditions and the Coverage Condition
+(described in ) are lifted. Termination is ensured by having a
fixed-depth recursion stack. If you exceed the stack depth you get a
sort of backtrace, and the opportunity to increase the stack depth
with N.
@@ -3364,7 +3371,7 @@ and you'd be right. That is why they are an experimental feature.
================ END OF Linear Implicit Parameters commented out -->
-
+Explicitly-kinded quantification
@@ -3484,7 +3491,6 @@ including an operational type class context, is legal:
On the left or right (see f4, for example)
of a function arrow
- On the right of a function arrow (see ) As the argument of a constructor, or type of a field, in a data type declaration. For
example, any of the f1,f2,f3,g1,g2 above would be valid
field type signatures.
@@ -4056,6 +4062,81 @@ 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
+
+The only predefined instance is the obvious one to make strings work as usual:
+
+instance IsString [Char] where
+ fromString cs = cs
+
+The class IsString 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 GHC.Exts.
+
+
+Haskell's defaulting mechanism is extended to cover string literals, when is specified.
+Specifically:
+
+
+Each type in a default declaration must be an
+instance of Numor of IsString.
+
+
+
+The standard defaulting rule (Haskell Report, Section 4.3.4)
+is extended thus: defaulting applies when all the unresolved constraints involve standard classes
+orIsString; and at least one is a numeric class
+orIsString.
+
+
+
+
+A small example:
+
+module Main where
+
+import GHC.Exts( IsString(..) )
+
+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 +4248,14 @@ Tim Sheard is going to expand it.)
(It would make sense to do so, but it's hard to implement.)
+
+ Furthermore, 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.
@@ -4786,7 +4875,7 @@ Because the preprocessor targets Haskell (rather than Core),
-
+Bang patterns
Bang patterns
@@ -4801,7 +4890,7 @@ than the material below.
Bang patterns are enabled by the flag .
-
+Informal description of bang patterns
@@ -4856,7 +4945,7 @@ is part of the syntax of let bindings.
-
+Syntax and semantics
@@ -4930,7 +5019,7 @@ a module.
-
+Assertions
Assertions
@@ -5899,12 +5988,6 @@ The following are good consumers:
- length
-
-
-
-
-++ (on its first argument)