A first ontology¶
This chapter describes the language as built. Every program in it was checked
with len check, and the output shown is what the command printed.
Before anything can be claimed, we have to say what we are talking about. In LEN that is the ontology level: the kinds of things there are, the particular things, the relations they can stand in, and which statements about them we assert or put forward. Nothing at this level is proved, tested or weighed. It is vocabulary, and a few sentences written in it.
A module, types and constants¶
A file opens with the name of its module, which is the name of the file:
module club
A reading club has people and clubs. Each is a type:
type Person
type Club
A type has no fields and no definition. It is a name for a kind of thing. Particular things are constants, and each has a type:
const Ada, Ben: Person
const Readers: Club
A relation¶
A relation says how things can be connected. It names its places and gives each a type:
rel member(person: Person, club: Club)
member does not say who is a member of what. It says that membership is
something a person and a club can have between them.
A fact and a claim¶
A fact is a statement we assert:
fact member(Ada, Readers)
A claim is a statement we put forward, with a name, so that later work can be about it:
claim BenIsAMember {
member(Ben, Readers)
}
The difference is the point of the language. A fact is taken as given. A claim is open: nothing has settled it, and the later parts of this book are about what could.
Checking¶
Put these declarations in a file, club.len, and check it:
len check club.len
The command prints nothing and exits with 0. It has read the file, resolved every name and checked every type.
Now make two mistakes. Swap the places of a fact, and name a club that was never declared:
module wrong
type Person
type Club
const Ada: Person
const Readers: Club
rel member(person: Person, club: Club)
fact member(Readers, Ada)
fact member(Ada, Writers)
wrong.len:11:13: error[LEN-TYPE-001]: `Readers` is of type `Club`, expected `Person`
wrong.len:11:22: error[LEN-TYPE-001]: `Ada` is of type `Person`, expected `Club`
wrong.len:12:18: error[LEN-NAME-001]: `Writers` is not declared
The command exits with 1. Each line names the file, the line and the column, then a code that identifies the rule, then the mistake. The types did their work before any reasoning started: a statement that puts a club where a person belongs is not false, it is not a statement.
Writing a relation the way it is said¶
member(Ben, Readers) is exact and reads badly. A relation may carry a
form: a second way of writing it, with a word between its places.
rel member(person: Person, club: Club) {
form english: person belongs_to club
}
claim BenIsAMember {
Ben belongs_to Readers
}
A form adds no meaning. The claim above is the same claim as before, and
len check reads it as member(Ben, Readers). A relation may have several
forms, and the checker reports a sentence that two of them could mean.
What we have¶
| Word | Says |
|---|---|
module |
this file is this module |
type |
there is this kind of thing |
const |
there is this thing, of this type |
rel |
things of these types can be connected this way |
form |
the relation may also be written like this |
fact |
this statement is asserted |
claim |
this statement is put forward, under a name |
So far a claim is only a named sentence. The rest of this chapter gives it a meaning, in a logic or in a programming language, and asks for the work that would settle it.