Changes between Version 1 and Version 2 of Language/Variables

Show
Ignore:
Timestamp:
06/24/09 10:41:44 (6 years ago)
Author:
benl (IP: 150.203.160.45)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language/Variables

    v1 v2  
    33 
    44{{{ 
    5 Var   ::=   Lower | VarSym       -- plain variable      eg: length, map_, wibble23 
    6 Con   ::=   Upper | VarSym       -- plain constructor   eg: Int, Cons, Tuple2 
     5Var    ::=   Lower | VarSym       -- plain variable      eg: length, map_, wibble23 
     6Con    ::=   Upper | VarSym       -- plain constructor   eg: Int, Cons, Tuple2 
    77 
    8 RVar  ::=   %  Var               -- region variable     eg: %r1, %const 
    9 ECon  ::=   !  Con               -- effect constructor  eg: !Read, !Write 
     8VarSym ::= Lower | Upper | Digit | _ | ' 
    109 
    11 TyVar ::=   Var                  -- value or higher kinded type variable 
    12        |    % Var                -- region variable 
    13        |    ! Var                -- effect variable 
    14        |    $ Var                -- closure variable 
     10TyVar  ::=   Var                  -- value or higher kinded type variable 
     11        |    % Var                -- region variable 
     12        |    ! Var                -- effect variable 
     13        |    $ Var                -- closure variable 
    1514 
    16 VarSym := Lower | Upper | Digit | _ | ' 
     15RVar   ::=   %  Var               -- variable in the region namespace     eg: %r1, %const 
     16ECon   ::=   !  Con               -- constructor in the effect namespace  eg: !Read, !Write 
    1717}}} 
    1818 
     19[[br]] 
     20== Name spaces == 
     21Each variable lies in a particular names space. There are several name spaces, and the five basic ones are: 
     22 
     23||'''Namespace'''||'''qualifier'''||'''associated kind'''||'''example'''|| 
     24||Values||none||not applicable||length, map, Cons, Nothing|| 
     25||Value types||none||*||List, Tuple, the m in (forall (m :: * -> *). Monad m => a -> m a)|| 
     26||Region types||%||%||%r1, %const|| 
     27||Effect types||!||!||!e1, !Read, !Write, !Console|| 
     28||Closure types||$||$||$c1, $c2|| 
     29 
     30All variables in the region, effect and closure name spaces are prefixed with a qualifier, which is also the symbol for that kind. 
     31 
     32The general rule is that a variable exists in the name space of its resulting kind. For example: 
     33 
     34||The a in ||forall a. a -> a|| has kind *|| and is in name space * (value types)|| 
     35||The m in ||forall (m :: * -> *). ... || has kind (* -> *) || and is in name space * (value types)|| 
     36||The constructor|| Read|| has kind (% -> !)|| and is in name space ! (effects)|| 
     37||The variable||%r1||has kind %||and is in name space % (regions)|| 
     38 
     39The exception to this rule is the kinds given to type class constraints such as Eq and Mutable. Eq has kind * -> + and Mutable has kind % -> +, but we put the constructors Eq and Mutable in the * (type) name space instead of making a new name space for +. We follow Haskell in this respect. Note that although Haskell98 doesn't assign a kind to type class constraints, constrains and type constructors are still in the same name space, so you can't have a type constructor Eq as well as a type class Eq in the same scope. 
     40 
     41There is also a name space associated with each type. Projection function are added to these name spaces by defining data types to have fields, and by explicitly declaring projection dictionaries. For example, if {{{xs}}} has type {{{List Int}}} then the expression {{{xs.length}}} calls the projection function {{{length}}} located in the name space for {{{List Int}}}. If there is no {{{length}}} projection in the {{{List Int}}} name space, but there is in a more general name space such as {{{List a}}}, then that is used instead. 
     42 
     43 
     44