Changes between Version 6 and Version 7 of Language

Show
Ignore:
Timestamp:
06/24/09 09:01:34 (5 years ago)
Author:
benl (IP: 150.203.160.45)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v6 v7  
    1919{{{ 
    2020ExportDecl 
    21     ::= export Var 
    22      |  export type Con 
     21    ::= export  Var 
     22     |  export type  Con 
    2323}}} 
    2424 
     
    7373{{{ 
    7474InfixDecl 
    75     ::= infixl  Int  Symbol;+ 
    76      |  infixr  Int  Symbol;+ 
    77      |  infix   Int  Symbol;+ 
     75    ::= infixl  Int  Symbol;+                  -- left associative 
     76     |  infixr  Int  Symbol;+                  -- right associative 
     77     |  infix   Int  Symbol;+                  -- non-associative 
    7878}}} 
    7979 
    8080Sets the precedence and associativity of an infix binary operator. 
     81 
    8182[[BR]] 
    8283 
    83 == !TypeKind === 
     84== !TypeKind == 
     85 
     86{{{ 
     87TypeKind  
     88    ::=  type  Con  ::  Kind  
     89 
     90}}} 
    8491 
    8592Sets the kind of an abstract type constructor. 
    8693 
     94[[br]] 
    8795 
    8896 
     
    9098{{{ 
    9199TypeSynonym 
    92     ::=  type  Con  Var+  =  Type  
     100    ::=  type  Con  TyVar+  =  Type  
    93101}}} 
    94102 
    95103Type synonyms are not implemented yet #16. 
     104 
     105[[br]] 
     106 
     107== !DataDecl == 
     108{{{ 
     109DataDecl 
     110    ::=  data  Con  TyVar*  =  CtorDecl  |CtorDecl+ 
     111 
     112CtorDecl 
     113    ::=  Con  SimpleType* 
     114     |   Con  {  DataField;+  } 
     115 
     116DataField 
     117    ::=  SimpleType                                  -- unnamed primary field 
     118     |   Var  ::  SimpleType                         -- named primary field  
     119     |   .  Var  ::  SimpleType  =  Exp              -- secondary field with initial value 
     120}}} 
     121 
     122As we want to support type constraints on constructors #87, and constraints are separated by a commas, we separate data fields with semicolons.  This is a difference from Haskell, but should allow us to use the offside rule when listing the fields of a constructor #88. 
     123 
     124Data type definitions are elaborated, so you don't need to mention all the region, effect and closure variables in the types of constructor arguments. If the type of a constructor argument is missing a region, effect or closure variable, then the corresponding argument of the surrounding type constructor is used. 
     125 
     126Primary fields become arguments of the constructor function, but secondary fields do not. For example, the following declaration: 
     127 
     128{{{ 
     129data Animal 
     130       = Cat   { name :: String; weight :: Int } 
     131       | Mouse { name :: String; age :: Int; .length :: Int = 5 } 
     132}}} 
     133 
     134Generates the following (elaborated) constructors: 
     135 
     136{{{ 
     137Cat   :: forall %r1. String %r1 -> Int %r1 -> Animal %r1 
     138Mouse :: forall %r1. String %r1 -> Int %r1 -> Animal %r1 
     139}}} 
     140 
     141Note that {{{Cat}}} has an argument for its name and weight of lives left, but {{{Mouse}}} only has arguments for its name and age. The length field is initialized to {{{5}}} when a Mouse is constructed. Secondary fields can still be accessed via the projection syntax: 
     142 
     143{{{ 
     144do  fred  = Mouse "Fred" 3 
     145    print fred.name          -- prints "Fred" 
     146    print fred.length        -- prints "5" 
     147 
     148    fred.length := 6         -- changes Fred's length 
     149    print fred.length        -- prints "6" 
     150}}} 
     151