From 79eedc76088e54ff1bd01855fad2e32eecd04be8 Mon Sep 17 00:00:00 2001 From: simonpj Date: Wed, 9 Mar 2005 17:47:09 +0000 Subject: [PATCH] [project @ 2005-03-09 17:47:09 by simonpj] Document infix type operators --- ghc/docs/users_guide/glasgow_exts.xml | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ghc/docs/users_guide/glasgow_exts.xml b/ghc/docs/users_guide/glasgow_exts.xml index 4836749..0b73fbe 100644 --- a/ghc/docs/users_guide/glasgow_exts.xml +++ b/ghc/docs/users_guide/glasgow_exts.xml @@ -925,11 +925,11 @@ Nevertheless, they can be useful when defining "phantom types". -Infix type constructors and classes +Infix type constructors, classes, and type variables -GHC allows type constructors and classes to be operators, and to be written infix, very much -like expressions. More specifically: +GHC allows type constructors, classes, and type variables to be operators, and +to be written infix, very much like expressions. More specifically: A type constructor or class can be an operator, beginning with a colon; e.g. :*:. @@ -955,6 +955,21 @@ like expressions. More specifically: + A type variable can be an (unqualified) operator e.g. +. + The lexical syntax is the same as that for variable operators, excluding "(.)", + "(!)", and "(*)". In a binding position, the operator must be + parenthesised. For example: + + type T (+) = Int + Int + f :: T Either + f = Left 3 + + liftA2 :: Arrow (~>) + => (a -> b -> c) -> (e ~> a) -> (e ~> b) -> (e ~> c) + liftA2 = ... + + + Back-quotes work as for expressions, both for type constructors and type variables; e.g. Int `Either` Bool, or Int `a` Bool. Similarly, parentheses work the same; e.g. (:*:) Int Bool. @@ -973,14 +988,6 @@ like expressions. More specifically: Function arrow is infixr with fixity 0. (This might change; I'm not sure what it should be.) - - The only thing that differs between operators in types and operators in expressions is that - ordinary non-constructor operators, such as + and * - are not allowed in types. Reason: the uniform thing to do would be to make them type - variables, but that's not very useful. A less uniform but more useful thing would be to - allow them to be type constructors. But that gives trouble in export - lists. So for now we just exclude them. - -- 1.7.10.4