From cb23a258bc0fc334f8ab61778bae656f6331ecf4 Mon Sep 17 00:00:00 2001 From: simonpj Date: Tue, 29 May 2001 15:37:16 +0000 Subject: [PATCH] [project @ 2001-05-29 15:37:16 by simonpj] Stuff about scoped type variables --- ghc/docs/users_guide/glasgow_exts.sgml | 40 +++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 44fcad0..c3b06ec 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -600,7 +600,10 @@ qualifier list has just one element, a boolean expression. The Foreign Function Interface language specification - (included in this manual, in ). + (included in this manual, in ). + You must use the command-line option + to make GHC understand the foreign declarations + defined by the FFI. @@ -658,8 +661,8 @@ of the foreign function interface in GHC. When generating C (using the directive), one can assist the -C compiler in detecting type errors by using the -#include directive -to provide .h files containing function headers. +C compiler in detecting type errors by using the directive +() to provide .h files containing function headers. @@ -2230,15 +2233,25 @@ For example, all of these are legal: - All the type variables mentioned in a pattern, +All the type variables mentioned in a pattern, that are not already in scope, are brought into scope by the pattern. We describe this set as the type variables bound by the pattern. - +For example: + + f (x::a) = let g (y::(a,b)) = fst y + in + g (x,True) + +The pattern (x::a) brings the type variable +a into scope, as well as the term +variable x. The pattern (y::(a,b)) +contains an occurrence of the already-in-scope type variable a, +and brings into scope the type variable b. - + The type variables thus brought into scope may be mentioned in ordinary type signatures or pattern type signatures anywhere within @@ -2246,8 +2259,8 @@ their scope. - + In ordinary type signatures, any type variable mentioned in the signature that is in scope is not universally quantified. @@ -2261,21 +2274,19 @@ signature that is in scope is not universally quantified. Ordinary type signatures do not bring any new type variables into scope (except in the type signature itself!). So this is illegal: - f :: a -> a f x = x::a - It's illegal because a is not in scope in the body of f, so the ordinary signature x::a is equivalent to x::forall a.a; and that is an incorrect typing. - + There is no implicit universal quantification on pattern type signatures, nor may one write an explicit forall type in a pattern @@ -2283,8 +2294,8 @@ type signature. The pattern type signature is a monotype. - + The type variables in the head of a class or instance declaration @@ -2358,14 +2369,15 @@ Result type signatures are not yet implemented in Hugs. Where a pattern type signature can occur + A pattern type signature can occur in any pattern, but there are restrictions on pattern bindings: - A pattern type signature can be on an arbitrary sub-pattern, not -just on a variable: +A pattern type signature can be on an arbitrary sub-pattern, not +ust on a variable: @@ -2399,8 +2411,8 @@ in case expressions: - + To avoid ambiguity, the type after the “::” in a result pattern signature on a lambda or case must be atomic (i.e. a single -- 1.7.10.4