-
Notifications
You must be signed in to change notification settings - Fork 5
Syntax
A Celf file is a series of top level declarations that declares a CLF signature, defines some CLF terms, and runs queries to find CLF terms.
-
id : KIND.
Declares a new type family id. See Type Family Declarations. -
id : NEG-TYPE.
Declares a new term constant. See Types. -
id : NEG-TYPE = TERM.
Defines a constant of a particular type in terms of existing constants. See Types and Terms. -
#query ? ? ? NUM NEG-TYPE.
Searches for (the?
is either a natural numberNUM
or a wildcard*
). See Queries. -
#trace ? POS-TYPE.
Searches for (the?
is either a natural numberNUM
or a wildcard*
). See Queries. -
#exec ? POS-TYPE.
Searches for (the?
is either a natural numberNUM
or a wildcard*
). See Queries. -
#mode id MODEDECL.
Declares a mode for the type familyid
. See Modes.
There are three sorts of objects: values, which have positive type; terms, which have negative type; and expressions, which have monadic type. Patterns are a different sort of thing - they match values in the same way that ML patterns match ML values.
Values V
:
-
N
- constructs a value from a term, and has typeA
. -
@N
- constructs a value from a term using only affine variables, and has type@A
. -
!N
- constructs a value from a term using only persistent variables, and has type!A
. -
1
- constructs a (multiplicative) unit of type1
. -
[V1,V2]
- constructs a (multiplicative) tuple of typeEXISTS p:S1. S2
(ifV1
has typeS1
andV2
has typeS2
). N-arty tuples are allowed:[V1,V2,V3,V4]
is syntactic sugar for[V1,[V2,[V3,V4]]]
. Note that special cases ofEXISTS p:S1. S2
areExists x. S2
andS1 * S2
.
An example of the syntax of values can be found in tests/syntax-values.clf.
Terms N, M
:
-
< N, M >
- A (additive) pair term; has typeA & B
ifN
is a term of typeA
andM
is a term of typeB
. Note that the spaces around the curly braces are critical:<a,b>
will be treated as the identifier<a
, followed by a comma, followed by the identifierb>
, and not as the pair ofa
andb
. (Is this a bug?) -
\p.N
- An implication: has typePI p:S. A
ifp
is a pattern of typeS
andN
is a term of typeA
. -
{E}
- A monadic term; has type{S}
ifE
is an expression of typeS
.
Expressions E
:
-
let {p} = M in E
- whereM
has type{S}
andp
is a pattern matching typeS
. -
V
-
Patterns p
:
-
x
- -
@x
- -
!x
- -
1
- matches any (multiplicative) unit of type1
. -
[p1,p2]
- matches (multiplicative) tuples of typeEXISTS p:S1. S2
. N-arty patterns are allowed:[p1,p2,p3,p4]
is syntactic sugar for[p1,[p2,[p3,p4]]]
. Note that special cases ofEXISTS p:S1. S2
areExists x. S2
andS1 * S2
.