Items
Syntax
Item :
TypeDefinition
| Declaration
| Definition
Items are the primary building block of Par programs.
Definitions
Syntax
Declaration :
dec
ID:
TypeDefinition :
def
ID Annotation?=
Expression
def
defines a global definition usable throughout the file in which it was defined.
It can be used as many times as one desires, instantiating itself every time it’s used.
// define a static value
dec unit : !
def unit = !
// or all-in-one
def unit: ! = !
// define a function
def negate: [Bool] Bool = [b] b {
.true! => .false!
.false! => .true!
}
// define a function receiving types
dec pop : [type T] [List<T>] (Option<T>) List<T>
def pop = [type T] [list] list {
.empty! => (.none!) .empty!
.item(head) tail => (.some head) tail
}
Type Definitions
Syntax
TypeDefinition :
type
ID TypeParameters?=
TypeTypeParameters :
<
TypeParameter (,
TypeParamter)*,
?>
TypeParameter :
ID
A type definition defines a type alias, not a “new type”. All types in Par are structural.
// simple type alias
type Boolean = Bool
// the definition of Bool
type Bool = either {
.true!
.false!
}
// parameterized type alias
type Option<T> = either {
.none!
.some T
}