| 71 | | These should be removed in favor of Haskell/GHC style pragmas #86. |
| 72 | | |
| 73 | | [[br]] |
| 74 | | |
| 75 | | |
| 76 | | == !InfixDecl == |
| 77 | | |
| 78 | | {{{ |
| 79 | | InfixDecl |
| 80 | | ::= infixl Int Symbol;+ -- left associative |
| 81 | | | infixr Int Symbol;+ -- right associative |
| 82 | | | infix Int Symbol;+ -- non-associative |
| 83 | | }}} |
| 84 | | |
| 85 | | Sets the precedence and associativity of an infix binary operator. |
| 86 | | |
| 87 | | [[BR]] |
| 88 | | |
| 89 | | == !TypeKind == |
| 90 | | |
| 91 | | {{{ |
| 92 | | TypeKind |
| 93 | | ::= type Con :: Kind |
| 94 | | |
| 95 | | }}} |
| 96 | | |
| 97 | | Sets the kind of an abstract value type constructor. |
| 98 | | |
| 99 | | [[br]] |
| 100 | | |
| 101 | | |
| 102 | | == !TypeSynonym == |
| 103 | | {{{ |
| 104 | | TypeSynonym |
| 105 | | ::= type Con TyVar+ = Type |
| 106 | | }}} |
| 107 | | |
| 108 | | Type synonyms are not implemented yet #16. |
| 109 | | |
| 110 | | [[br]] |
| 111 | | |
| 112 | | == !DataDecl == |
| 113 | | {{{ |
| 114 | | DataDecl |
| 115 | | ::= data Con TyVar* = CtorDecl |CtorDecl+ |
| 116 | | |
| 117 | | CtorDecl |
| 118 | | ::= Con SimpleType* |
| 119 | | | Con { DataField;+ } |
| 120 | | |
| 121 | | DataField |
| 122 | | ::= SimpleType -- unnamed primary field |
| 123 | | | Var :: SimpleType -- named primary field |
| 124 | | | . Var :: SimpleType = Exp -- secondary field with initial value |
| 125 | | }}} |
| 126 | | |
| 127 | | As 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. |
| 128 | | |
| 129 | | Data 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. |
| 130 | | |
| 131 | | Primary fields become arguments of the constructor function, but secondary fields do not. For example, the following declaration: |
| 132 | | |
| 133 | | {{{ |
| 134 | | data Animal |
| 135 | | = Cat { name :: String; weight :: Int } |
| 136 | | | Mouse { name :: String; age :: Int; .length :: Int = 5 } |
| 137 | | }}} |
| 138 | | |
| 139 | | Generates the following (elaborated) constructors: |
| 140 | | |
| 141 | | {{{ |
| 142 | | Cat :: forall %r1. String %r1 -> Int %r1 -> Animal %r1 |
| 143 | | Mouse :: forall %r1. String %r1 -> Int %r1 -> Animal %r1 |
| 144 | | }}} |
| 145 | | |
| 146 | | Note 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: |
| 147 | | |
| 148 | | {{{ |
| 149 | | do fred = Mouse "Fred" 3 |
| 150 | | print fred.name -- prints "Fred" |
| 151 | | print fred.length -- prints "5" |
| 152 | | |
| 153 | | fred.length := 6 -- changes Fred's length |
| 154 | | print fred.length -- prints "6" |
| 155 | | }}} |
| 156 | | |
| 157 | | [[br]] |
| 158 | | |
| 159 | | |
| 160 | | == !EffectDecl == |
| 161 | | |
| 162 | | {{{ |
| 163 | | EffectDecl |
| 164 | | ::= effect ECon :: Kind |
| 165 | | }}} |
| 166 | | |
| 167 | | Defines a new effect constructor and sets its kind. The result kind of the constructor must be !. |
| 168 | | |
| 169 | | Inference involving effect constructors of kinds other than {{{!}}} and {{{(% -> !)}}} is not well tested #89. |
| 170 | | |
| 171 | | [[br]] |
| 172 | | |
| 173 | | == !RegionDecl == |
| 174 | | |
| 175 | | {{{ |
| 176 | | RegionDecl |
| 177 | | ::= region RVar (:- TyConstraint ,TyConstraint*)? |
| 178 | | }}} |
| 179 | | |
| 180 | | Defines a top-level (global) region. |
| 181 | | |
| 182 | | Although explicitly binding top-level region variables is not nessesary, it can be useful to define the constraints on a global region in a single place in the source file, instead of trying to repeat them in each type signature that uses it. For example: |
| 183 | | |
| 184 | | {{{ |
| 185 | | region %r :- Const %r |
| 186 | | |
| 187 | | pi :: Float %r |
| 188 | | pi = 3.1415926535 |
| 189 | | |
| 190 | | e :: Float %r |
| 191 | | e = 2.71828183 |
| 192 | | }}} |
| 193 | | |
| 194 | | [[br]] |
| 195 | | |
| 196 | | == !ClassDecl == |
| 197 | | |
| 198 | | {{{ |
| 199 | | ClassDecl |
| 200 | | ::= class Con :: Kind -- abstract class constraint |
| 201 | | | class Con TyVar+ where { TypeSig;+ } -- value type class definition |
| 202 | | }}} |
| 203 | | |
| 204 | | The return kind of abstract class constraints must be {{{+}}}. We don't yet support default instances in type class declarations #90. |
| 205 | | |
| 206 | | [[br]] |
| 207 | | |
| 208 | | == !InstanceDecl == |
| 209 | | |
| 210 | | {{{ |
| 211 | | InstanceDecl |
| 212 | | ::= instance Con SimpleType+ where { Binding;+ } |
| 213 | | }}} |
| 214 | | |
| 215 | | [[br]] |
| 216 | | |
| 217 | | == !ProjectionDecl == |
| 218 | | |
| 219 | | {{{ |
| 220 | | ProjectionDecl |
| 221 | | ::= project Con SimpleType* where { (TypeSig|Binding)+ } -- projection dictionary |
| 222 | | | project Con SimpleType* with { Var+ } -- projection punning |
| 223 | | }}} |
| 224 | | |
| 225 | | The first form defines some projection functions associated with a given type. Presently, all projections associated with a type must be declared in the same projection declaration and in the same source module, but there is a plan to relax this #7. |
| 226 | | |
| 227 | | If two projection dictionaries are defined for types that overlap, eg List Int and List a, then the result is currently undefined. There is a ticket to fix this #40. |
| 228 | | |
| 229 | | The projection punning syntax imports bindings at top level into the projection name space. For example: |
| 230 | | |
| 231 | | {{{ |
| 232 | | project Set a with { insert; delete; size } |
| 233 | | }}} |
| 234 | | |
| 235 | | Is equivalent to |
| 236 | | {{{ |
| 237 | | project Set a where { insert = insert; delete = delete; size = size } |
| 238 | | }}} |
| 239 | | |
| 240 | | This is useful when implementations of {{{insert}}}, {{{delete}}} and {{{size}}} are in the current module, but only the type {{{Set}}} is exported. All projections associated with a certain type are exported when the type is. |
| 241 | | |
| 242 | | |
| 243 | | == !TypeSig == |
| 244 | | |
| 245 | | {{{ |
| 246 | | TypeSig |
| 247 | | ::= Var :: Type |
| 248 | | }}} |
| 249 | | |
| 250 | | |