X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fdocs%2Fusers_guide%2Fglasgow_exts.sgml;h=5c809257b901db00a3b87676ca0789d79bea12c7;hb=277cd58374ee122c3ae4dc7d99a10971facaf830;hp=390697f719eebf1ef1b9c2e1e9532951e24a66ab;hpb=309003c9c2c7c480223f01cb5dd97c25a793eec6;p=ghc-hetmet.git diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 390697f..5c80925 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -96,6 +96,13 @@ Executive summary of our extensions: + Data types with no constructors + + See . + + + + Parallel list comprehensions An extension to the list comprehension syntax to support @@ -135,6 +142,9 @@ Executive summary of our extensions: Generic classes: + (Note: support for generic classes is currently broken + in GHC 5.02). + Generic class declarations allow you to define a class whose methods say how to work over an arbitrary data type. Then it's really easy to make any new type into an instance of @@ -415,6 +425,24 @@ The libraries documentatation gives more details on all these + +Data types with no constructors + +With the flag, GHC lets you declare +a data type with no constructors. For example: + + data S -- S :: * + data T a -- T :: * -> * + +Syntactically, the declaration lacks the "= constrs" part. The +type can be parameterised, but only over ordinary types, of kind *; since +Haskell does not have kind signatures, you cannot parameterise over higher-kinded +types. + +Such data types have only one value, namely bottom. +Nevertheless, they can be useful when defining "phantom types". + + Pattern guards @@ -592,111 +620,6 @@ qualifier list has just one element, a boolean expression. - - The foreign interface - - The foreign interface consists of the following components: - - - - The Foreign Function Interface language specification - (included in this manual, in ). - You must use the command-line option - to make GHC understand the foreign declarations - defined by the FFI. - - - - The Foreign module (see ) collects together several interfaces - which are useful in specifying foreign language - interfaces, including the following: - - - - The ForeignObj module (see ), for managing pointers from - Haskell into the outside world. - - - - The StablePtr module (see ), for managing pointers - into Haskell from the outside world. - - - - The CTypes module (see ) gives Haskell equivalents for the - standard C datatypes, for use in making Haskell bindings - to existing C libraries. - - - - The CTypesISO module (see ) gives Haskell equivalents for C - types defined by the ISO C standard. - - - - The Storable library, for - primitive marshalling of data types between Haskell and - the foreign language. - - - - - - -The following sections also give some hints and tips on the use -of the foreign function interface in GHC. - - -Using function headers - - - -C calls, function headers - - - -When generating C (using the directive), one can assist the -C compiler in detecting type errors by using the directive -() to provide .h files containing function headers. - - - -For example, - - - - - -#include "HsFFI.h" - -void initialiseEFS (HsInt size); -HsInt terminateEFS (void); -HsForeignObj emptyEFS(void); -HsForeignObj updateEFS (HsForeignObj a, HsInt i, HsInt x); -HsInt lookupEFS (HsForeignObj a, HsInt i); - - - - The types HsInt, - HsForeignObj etc. are described in . - - Note that this approach is only - essential for returning - floats (or if sizeof(int) != - sizeof(int *) on your architecture) but is a Good - Thing for anyone who cares about writing solid code. You're - crazy not to do it. - - - - - Multi-parameter type classes @@ -2508,15 +2431,28 @@ would get a monomorphic type. - -Pragmas - + + Pragmas - -GHC supports several pragmas, or instructions to the compiler placed -in the source code. Pragmas don't affect the meaning of the program, -but they might affect the efficiency of the generated code. - + pragma + + GHC supports several pragmas, or instructions to the + compiler placed in the source code. Pragmas don't normally affect + the meaning of the program, but they might affect the efficiency + of the generated code. + + Pragmas all take the form + +{-# word ... #-} + + where word indicates the type of + pragma, and is followed optionally by information specific to that + type of pragma. Case is ignored in + word. The various values for + word that GHC understands are described + in the following sections; any pragma encountered with an + unrecognised word is (silently) + ignored. INLINE pragma @@ -2588,17 +2524,23 @@ For example, in GHC's own <literal>UniqueSupply</literal> monad code, we have: <title>NOINLINE pragma - NOINLINE pragma -pragma, NOINLINE - +pragmaNOINLINE +NOTINLINE pragma +pragmaNOTINLINE -The NOINLINE pragma does exactly what you'd expect: it stops the -named function from being inlined by the compiler. You shouldn't ever -need to do this, unless you're very cautious about code size. +The NOINLINE pragma does exactly what you'd expect: +it stops the named function from being inlined by the compiler. You +shouldn't ever need to do this, unless you're very cautious about code +size. +NOTINLINE is a synonym for +NOINLINE (NOTINLINE is specified +by Haskell 98 as the standard way to disable inlining, so it should be +used if you want your code to be portable). + @@ -2728,6 +2670,42 @@ The RULES pragma lets you specify rewrite rules. It is described in + +DEPRECATED pragma + + +The DEPRECATED pragma lets you specify that a particular function, class, or type, is deprecated. +There are two forms. + + + +You can deprecate an entire module thus: + + module Wibble {-# DEPRECATED "Use Wobble instead" #-} where + ... + + +When you compile any module that import Wibble, GHC will print +the specified message. + + + + +You can deprecate a function, class, or type, with the following top-level declaration: + + + {-# DEPRECATED f, C, T "Don't use these" #-} + + +When you compile any module that imports and uses any of the specifed entities, +GHC will print the specified message. + + + +You can suppress the warnings with the flag . + + + @@ -3033,14 +3011,14 @@ The following are good producers: ++ - + map - + filter @@ -3090,8 +3068,14 @@ The following are good consumers: ++ (on its first argument) + + + foldr + + + map @@ -3285,6 +3269,9 @@ program even if fusion doesn't happen. More rules in PrelList.lhs Generic classes + (Note: support for generic classes is currently broken in + GHC 5.02). + The ideas behind this extension are described in detail in "Derivable type classes", Ralf Hinze and Simon Peyton Jones, Haskell Workshop, Montreal Sept 2000, pp94-105. @@ -3440,10 +3427,10 @@ So this too is illegal: class Foo a where op1 :: a -> Bool - op {| a :*: b |} (Inl x) = True + op1 {| a :*: b |} (x :*: y) = True op2 :: a -> Bool - op {| p :*: q |} (Inr y) = False + op2 {| p :*: q |} (x :*: y) = False (The reason for this restriction is that we gather all the equations for a particular type consructor into a single generic instance declaration.)