The GEB Manual
Table of Contents
 1 Links
 2 Getting Started
 3 Glossary
 4 Original Efforts
 5 Categorical Model
 6 Project Idioms and Conventions
 7 The Geb Model
 8 The GEB GUI
 9 Polynomial Specification
 10 The Simply Typed Lambda Calculus model
 11 Mixins
 12 Geb Utilities
 13 Testing
[in package GEBDOCS/DOCS]
Welcome to the GEB project.
1 Links
Here is the official repository
and HTML documentation for the latest version.
1.1 code coverage
For test coverage it can be found at the following links:
CCL test coverage: current under maintenance
Note that due to #34 CCL tests are not currently displaying
I recommend reading the CCL code coverage version, as it has proper tags.
Currently they are manually generated, and thus for a more accurate assessment see GEBTEST:CODECOVERAGE
2 Getting Started
Welcome to the GEB Project!
2.1 installation
This project uses common lisp, so a few dependencies are needed to get around the codebase and start hacking. Namely:
Emacs along with one of the following:
2.2 loading
Now that we have an environment setup, we can load the project, this can be done in a few steps.
Open the
REPL
(sbcl (terminal),Mx
sly,Mx
swank)For the terminal, this is just calling the common lisp implementation from the terminal.
user@system:gebdirectory % sbcl
.For Emacs, this is simply calling either
Mx sly
orMx slime
if you are using either sly or slime
From Emacs: open
geb.asd
and pressCck
(slycompileandloadfile
, orswankcompileandloadfile
if you are using swank).
Now that we have the file open, we can now load the system by writing:
;; only necessary for the first time!
(ql:quickload :geb/documentation)
;; if you want to load it in the future
(asdf:loadsystem :geb/documentation)
;; if you want to load the codbase and run tests at the same time
(asdf:testsystem :geb/documentation)
;; if you want to run the tests once the system is loaded!
(gebtest:runtests)
2.3 Geb as a binary
[in package GEB.ENTRY]
The standard way to use geb currently is by loading the code into one's lisp environment
(ql:quickload :geb)
However, one may be interested in running geb in some sort of compilation process, that is why we also give out a binary for people to use
An example use of this binary is as follows
mariari@Gensokyo % ./geb.image i "foo.lisp" e "geb.lambda.spec::*entry*" l v o "foo.pir"
mariari@Gensokyo % cat foo.pir
def *entry* x {
0
}%
mariari@Gensokyo % ./geb.image i "foo.lisp" e "geb.lambda.spec::*entry*" l v
def *entry* x {
0
}
./geb.image h
i input string Input geb file location
e entrypoint string The function to run, should be fully qualified I.E.
geb::mymain
l stlc boolean Use the simply typed lambda calculus frontend
o output string Save the output to a file rather than printing
v vampir string Return a vampir expression
h ? help boolean The current help message
starting from a file foo.lisp that has
(inpackage :geb.lambda.spec)
(defparameter *entry*
(typed unit geb:so1))
inside of it.
The command needs an entrypoint (e or entrypoint), as we are
simply call LOAD
on the given file, and need to know what to
translate.
from STLC
, we expect the form to be wrapped in the
GEB.LAMBDA.SPEC.TYPED which takes both the type and the value to
properly have enough context to evaluate.
It is advised to bind this to a parameter like in our example as e expects a symbol.
the l flag means that we are not expecting a geb term, but rather a lambda frontend term, this is to simply notify us to compile it as a lambda term rather than a geb term. In time this will go away
 [function] COMPILEDOWN &KEY VAMPIR STLC ENTRY (STREAM
*STANDARDOUTPUT*
)
3 Glossary

A closed type is a type that can not be extended dynamically. A good example of this kind of term is an ML ADT.
data Tree = Empty  Leaf Int  Node Tree Tree
In our lisp code we have a very similar convention:
(inpackage :geb.spec) (deftype substmorph () `(or substobj alias comp init terminal case pair distribute injectleft injectright projectleft projectright))
This type is closed, as only one of
GEB:SUBSTOBJ
,GEB:INJECTLEFT
,GEB:INJECTRIGHT
etc can form theGEB:SUBSTMORPH
type.The main benefit of this form is that we can be exhaustive over what can be found in
GEB:SUBSTMORPH
.(defun sohomobj (x z) (matchof substobj x (so0 so1) (so1 z) (alias (sohomobj (obj x) z)) ((coprod x y) (prod (sohomobj x z) (sohomobj y z))) ((prod x y) (sohomobj x (sohomobj y z)))))
If we forget a case, like
GEB:COPROD
it wanrs us with an non exhaustion warning.Meaning that if we update definitions this works well.
The main downside is that we can not extend the type after the fact, meaning that all interfaces on SOHOMOBJ must take the unaltered type. This is in stark contrast to open types. To find out more about the trade offs and usage in the codebase read the section Open Types versus Closed Types.

An open type is a type that can be extended by user code down the line. A good example of this in ML is the type class system found in Haskell.
In our code base, it is simple as creating a Common Lisp Object System (CLOS) term
(defclass <substobj> (directpointwisemixin) ())
and to create a child of it all we need to do is.
(defclass so0 (<substobj>) ())
Now any methods on
GEB:<SUBSTOBJ>
will coverGEB:SO0
(0
1
).
The main disadvantage of these is that exhaustion can not be checked, and thus the user has to know what methods to fill out. In a system with a bit more checks this is not a problem in practice. To find out more about the trade offs and usage in the codebase read the section Open Types versus Closed Types.
[glossaryterm] Common Lisp Object System (CLOS)
The object system found in CL. Has great features like a Meta Object Protocol that helps it facilitate extensions.
4 Original Efforts
Originally GEB started off as an Idris codebase written by the designer and creator of GEB, Terence Rokop, However further efforts spawned for even further formal verification by Artem Gureev. Due to this, we have plenty of code not in Common Lisp that ought to be a good read.
4.1 Geb's Idris Code
The Idris folder can be found in the gebidris folder provided in the codebase
At the time of this document, there is over 16k lines of Idris code written. This serves as the bulk of the POC that is GEB and is a treasure trove of interesting information surrounding category theory.
4.2 Geb's Agda Code
The Agda folder can be found in the gebagda folder provided in the codebase
The Agda codebase serves as a great place to view formally verified properties about the GEB project. Although Geb's Idris Code is written in a dependently typed language, it serves as reference example of GEB, while Geb's Agda Code serves as the mathematical formalism proving various conjectures about GEB
5 Categorical Model
Geb is organizing programming language concepts (and entities!) using category theory, originally developed by mathematicians, but very much alive in programming language theory. Let us look at a simple wellknown example: the category of sets and functions. It is the bread and butter example: sets $A,B,C,…$ play the role of objects, functions are arrows between objects $A—f→B$, and the latter compose as functions do, such that every path of matching functions $$A—f→B—g→C—h→D$$ composes to a corresponding composite function $$A—f;g;h→D$$ (or $h∘g∘f$ if you prefer) and we enjoy the luxury of not having to worry about the order in which we compose; for the sake of completeness, there are identify functions $A —\mathrm{id}_A→ A$ on each set $A$, serving as identities (which correspond to the composite of the empty path on an object). Sets and functions together form a category—based on function composition; thus, let's call this category sets'n'functions. This example, even “restricted” to finite sets'n'functions, will permeate through Geb.
One of the first lessons (in any introduction to category theory) about sets'n'functions is the characterization of products and disjoint sums of sets in terms of functions alone, i.e., without ever talking about elements of sets. Products and coproducts are the simplest examples of universal constructions. One of the first surprises follows suit when we generalize functions to partial functions, relations, or even multirelations: we obtain very different categories! For example, in the category sets'n'relations, the disjoint union of sets features as both a product and a coproduct, as a categorical construction.
Do not fear! The usual definition of products in terms of elements of sets are absolutely compatible with the universal construction in sets'n'functions. However we gain the possibility to compare the “result” of the universal constructions in sets'n'functions with the one in sets'n'relations (as both actually do have products).
for the purposes of Geb, many things can be expressed in analogy to the category of sets'n'functions; thus a solid understanding of the latter will be quite useful. In particular, we shall rely on the following universal constructions:
The construction of binary products $A × B$ of sets $A,B$, and the empty product $mathsf{1}$.
The construction of “function spaces” $B^A$ of sets $A,B$, called exponentials, i.e., collections of functions between pairs of sets.
The socalled currying of functions, $C^{(B^A)} cong C^{(A × B)}$, such that providing several arguments to a function can done either simultaneously, or in sequence.
The construction of sums (a.k.a. coproducts) $A + B$ of sets $A,B$, corresponding to forming disjoint unions of sets; the empty sum is $varnothing$.
Product, sums and exponentials are the (almost) complete tool chest for writing polynomial expressions, e.g., $$Ax^{sf 2} +x^{sf 1}  Dx^{sf 0}.$$ (We need these later to define “algebraic data types”.) In the above expression, we have sets instead of numbers/constants where $ mathsf{2} = lbrace 1, 2 rbrace$, $ mathsf{1} = lbrace 1 rbrace$, $ mathsf{0} = lbrace rbrace = varnothing$, and $A$ and $B$ are arbitrary (finite) sets. We are only missing a counterpart for the variable! Raising an arbitrary set to “the power” of a constant set happens to have a very natural counterpart: the central actor of the mostwell known fundamental result about categories, which generalizes Cayley's Theorem, i.e., the Yoneda embedding.
If you are familiar with the latter, buckle up and jump to Poly in Sets. Have a look at our streamlined account of The Yoneda Lemma if you are familiar with Cartesian closed categories, or take it slow and read up on the background in one of the classic or popular textbooks. Tastes tend to vary. However, Benjamin Pierce's Basic Category Theory for Computer Scientists deserves being pointed out as it is very amenable and covers the background we need in 60 short pages.
5.1 Morphisms
5.2 Objects
5.3 The Yoneda Lemma
5.4 Poly in Sets
6 Project Idioms and Conventions
The Geb Project is written in Common Lisp, which means the authors have a great choice in freedom in how the project is laid out and operates. In particular the style of Common Lisp here is a functional style with some OO idioms in the style of Smalltalk.
The subsections will outline many idioms that can be found throughout the codebase.
6.1 Spec Files, Main Files and Project Layout
[in package GEB.SPECS]
The codebase is split between many files. Each folder can be seen as
a different idea within geb itself! Thus the poly
has packages
revolving around polynomials, the geb
folder has packages regarding
the main types of geb Subst Obj and
Subst Morph, etc etc.
The general layout quirk of the codebase is that packages like
geb.package.spec
defines the specification for the base types for
any category we wish to model, and these reside in the specs
folder
not in the folder that talks about the packages of those types. This
is due to loading order issues, we thus load the specs
packages
before each of their surrounding packages, so that each package can
built off the last. Further, packages like geb.package.main
define
out most of the functionality of the package to be used by other
packages in geb.package
, then all of these are reexported out in the
geb.package
package
Further to make working with each package of an idea is easy, we have the main package of the folder (typically named the same as the folder name) reexport most important components so if one wants to work with the fully fledged versions of the package they can simply without having to import too many packages at once.
For example, the geb.poly.spec
defines out the types and data
structures of the Polynomial Types, this is then rexported
in geb.poly
, giving the module geb.poly
a convenient interface for
all functions that operate on geb.poly
.
6.2 Open Types versus Closed Types
closed type's and open type's both have their perspective tradeoff of openness versus exhaustiveness (see the linked articles for more on that). Due to this, they both have their own favorable applications. I would argue that a closed ADT type is great tool for looking at a function mathematically and treating the object as a whole rather than piecemeal. Whereas a more open extension is great for thinking about how a particular object/case behaves. They are different mindsets for different styles of code.
In the geb project, we have chosen to accept both styles, and allow both to coexist in the same setting. We have done this with a two part idiom.
(deftype substobj ()
`(or alias prod coprod so0 so1))
(defclass <substobj> (directpointwisemixin) ())
(defclass so0 (<substobj>) ...)
(defclass prod (<substobj>) ...)
The closed type is GEB:SUBSTOBJ
, filling and defining every structure
it knows about. This is a fixed idea that a programmer may statically
update and get exhaustive warnings about. Whereas GEB:<SUBSTOBJ>
is
the open interface for the type. Thus we can view GEB:<SUBSTOBJ>
as
the general idea of a GEB:SUBSTOBJ
. Before delving into how we combine
these methods, let us look at two other benefits given by GEB:<SUBSTOBJ>
We can put all the Mixins into the superclass to enforce that any type that extends it has the extended behaviors we wish. This is a great way to generically enhance the capabilities of the type without operating on it directly.
We can dispatch on
GEB:<SUBSTOBJ>
sinceDEFMETHOD
only works on Common Lisp Object System (CLOS) types and not generic types in CL.
Methods for closed and open types
With these pieces in play let us explore how we write a method in a way that is conducive to open and closed code.
(inpackage :geb)
(defgeneric topoly (morphism))
(defmethod topoly ((obj <substmorph>))
(typecaseof substmorph obj
(alias ...)
(substobj (error "Impossible")
(init 0)
(terminal 0)
(injectleft poly:ident)
(injectright ...)
(comp ...)
(case ...)
(pair ...)
(projectright ...)
(projectleft ...)
(distribute ...)
(otherwise (subclassresponsibility obj))))
(defmethod topoly ((obj <substobj>))
(declare (ignore obj))
poly:ident)
In this piece of code we can notice a few things:
We case on
GEB:SUBSTMORPH
exhaustivelyWe cannot hit the
GEB:<SUBSTOBJ>
case due to method dispatchWe have this
GEB.UTILS:SUBCLASSRESPONSIBILITY
function getting called.We can write further methods extending the function to other subtypes.
Thus the GEB:TOPOLY
function is written in such a way that it
supports a closed definition and open extensions, with
GEB.UTILS:SUBCLASSRESPONSIBILITY
serving to be called if an
extension a user wrote has no handling of this method.
Code can also be naturally written in a more open way as well, by simply running methods on each class instead.
Potential Drawback and Fixes
One nasty drawback is that we can't guarantee the method exists. In java this can easily be done with interfaces and then enforcing they are fulfilled. Sadly CL has no such equivalent. However, this is all easily implementable. If this ever becomes a major problem, it is trivial to implement this by registering the subclasses, and the perspective methods, and scouring the image for instance methods, and computing if any parent class that isn't the one calling responsibility fulfills it. Thus, in practice, you should be able to ask the system if any particular extension fulfills what extension sets that the base object has and give CI errors if they are not fulfilled, thus enforcing closed behavior when warranted.
6.3 ≺Types≻
These refer to the open type variant to a closed type. Thus when
one sees a type like GEB:GEB:SUBSTOBJ
. Read Open Types versus Closed Types for information on how to use them.
7 The Geb Model
[in package GEB]
Everything here relates directly to the underlying machinery of GEB, or to abstractions that help extend it.
7.1 The Categorical Interface
[in package GEB.MIXINS]
This covers the main Categorical interface required to be used and contained in various data structures
[genericfunction] DOM CATMORPH
Grabs the domain of the morphism. Returns a
CATOBJ
[genericfunction] CODOM CATMORPH
Grabs the codomain of the morphism. Returns a
CATOBJ
[genericfunction] CURRYPROD CATMORPH CATLEFT CATRIGHT
Curries the given product type given the product. This returns a
CATMORPH
.This interface version takes the left and right product type to properly dispatch on. Instances should specalize on the
CATRIGHT
argumentUse
GEB.MAIN:CURRY
instead.
7.2 Core Category
[in package GEB.SPEC]
The underlying category of GEB. With Subst Obj covering the shapes and forms (Objects) of data while Subst Morph deals with concrete Morphisms within the category.
From this category, most abstractions will be made, with
SUBSTOBJ
serving as a concrete type layout, with
SUBSTMORPH
serving as the morphisms between different
SUBSTOBJ
types. This category is equivalent to
finset.
A good example of this category at work can be found within the Booleans section.
7.2.1 Subst Obj
This section covers the objects of the SUBSTMORPH
category. Note that SUBSTOBJ
refers to the
closed type, whereas <SUBSTOBJ>
refers
to the open type that allows for user extension.

the class corresponding to
SUBSTOBJ
. See Open Types versus Closed Types
SUBSTOBJ
type is not a constructor itself, instead it's
best viewed as the sum type, with the types below forming the
constructors for the term. In ML we would write it similarly to:
type substobj = so0
 so1
 prod
 coprod

The PRODUCT object. Takes two
CATOBJ
values that get put into a pair.The formal grammar of PRODUCT is
(prod mcar mcadr)
where
PROD
is the constructor,MCAR
is the left value of the product, andMCADR
is the right value of the product.Example:
(gebgui::visualize (prod gebbool:bool gebbool:bool))
Here we create a product of two
GEBBOOL:BOOL
types.

the COPRODUCT object. Takes
CATOBJ
values that get put into a choice of either value.The formal grammar of PRODUCT is
(coprod mcar mcadr)
Where CORPOD is the constructor,
MCAR
is the left choice of the sum, andMCADR
is the right choice of the sum.Example:
(gebgui::visualize (coprod so1 so1))
Here we create the boolean type, having a choice between two unit values.

The Initial Object. This is sometimes known as the VOID type.
the formal grammar of
SO0
isso0
where
SO0
isTHE
initial object.Example
lisp

The Terminal Object. This is sometimes referred to as the Unit type.
the formal grammar or
SO1
isso1
where
SO1
isTHE
terminal objectExample
(coprod so1 so1)
Here we construct
GEBBOOL:BOOL
by simply stating that we have the terminal object on either side, giving us two possible ways to fill the type.(>left so1 so1) (>right so1 so1)
where applying
>LEFT
gives us the left unit, while>RIGHT
gives us the right unit.
The Accessors specific to Subst Obj
7.2.2 Subst Morph
The overarching types that categorizes the SUBSTMORPH
category. Note that SUBSTMORPH
refers to the
closed type, whereas <SUBSTMORPH>
refers
to the open type that allows for user extension.

The morphisms of the
SUBSTMORPH
category

the class type corresponding to
SUBSTMORPH
. See Open Types versus Closed Types
SUBSTMORPH
type is not a constructor itself, instead it's
best viewed as the sum type, with the types below forming the
constructors for the term. In ML we would write it similarly to:
type substmorph = comp
 substobj
 case
 init
 terminal
 pair
 distribute
 injectleft
 injectright
 projectleft
 projectright
Note that an instance of SUBSTOBJ
, acts like the identity
morphism to the layout specified by the given SUBSTOBJ
. Thus
we can view this as automatically lifting a SUBSTOBJ
into a
SUBSTMORPH

The composition morphism. Takes two
CATMORPH
values that get applied in standard composition order.The formal grammar of
COMP
is(comp mcar mcadr)
which may be more familiar as
g 。f
Where
COMP
( 。) is the constructor,MCAR
(g) is the second morphism that gets applied, andMCADR
(f) is the first morphism that gets applied.Example:
(gebgui::visualize (comp (<right so1 gebbool:bool) (pair (<left so1 gebbool:bool) (<right so1 gebbool:bool))))
In this example we are composing two morphisms. the first morphism that gets applied (
PAIR
...) is the identity function on the type (PROD
SO1
GEBBOOL:BOOL
), where we pair the left projection and the right projection, followed by taking the right projection of the type.Since we know (
COMP
f id) is just f per the laws of category theory, this expression just reduces to(<right so1 gebbool:bool)

Eliminates coproducts. Namely Takes two
CATMORPH
values, one gets applied on the left coproduct while the other gets applied on the right coproduct. The result of eachCATMORPH
values must be the same.The formal grammar of
CASE
is:(mcase mcar mcadr)
Where
MCASE
is the constructor,MCAR
is the morphism that gets applied to the left coproduct, andMCADR
is the morphism that gets applied to the right coproduct.Example:
(comp (mcase gebbool:true gebbool:not) (>right so1 gebbool:bool))
In the second example, we inject a term with the shape
GEBBOOL:BOOL
into a pair with the shape (SO1
×GEBBOOL:BOOL
), then we useMCASE
to denote a morphism saying.IF
the input is of the shapeSO1
(0
1
), then give us True, otherwise flip the value of the boolean coming in.

The INITIAL Morphism, takes any
CATOBJ
and creates a moprhism fromSO0
(also known as void) to the object given.The formal grammar of INITIAL is
(init obj)
where
INIT
is the constructor.OBJ
is the type of object that will be conjured up fromSO0
, when the morphism is applied onto an object.Example:
(init so1)
In this example we are creating a unit value out of void.

The
TERMINAL
morphism, Takes anyCATOBJ
and creates a morphism from that object toSO1
(also known as unit).The formal grammar of
TERMINAL
is(terminal obj)
where
TERMINAL
is the constructor.OBJ
is the type of object that will be mapped toSO1
, when the morphism is applied onto an object.Example:
(terminal (coprod so1 so1)) (gebgui::visualize (terminal (coprod so1 so1))) (comp value (terminal (codomain value))) (comp true (terminal bool))
In the first example, we make a morphism from the corpoduct of
SO1
andSO1
(essentiallyGEBBOOL:BOOL
) toSO1
.In the third example we can proclaim a constant function by ignoring the input value and returning a morphism from unit to the desired type.
The fourth example is taking a
GEBBOOL:BOOL
and returningGEBBOOL:TRUE
.

Introduces products. Namely Takes two
CATMORPH
values. When thePAIR
morphism is applied on data, these twoCATMORPH
's are applied to the object, returning a pair of the resultsThe formal grammar of constructing an instance of pair is:
(pair mcar mcdr)
where
PAIR
is the constructor,MCAR
is the left morphism, andMCDR
is the right morphismExample:
(pair (<left so1 gebbool:bool) (<right so1 gebbool:bool)) (gebgui::visualize (pair (<left so1 gebbool:bool) (<right so1 gebbool:bool)))
Here this pair morphism takes the pair
SO1
(0
1
) ×GEBBOOL:BOOL
, and projects back the left fieldSO1
as the first value of the pair and projects back theGEBBOOL:BOOL
field as the second values.

The distributive law

The left injection morphism. Takes two
CATOBJ
values. It is the dual ofINJECTRIGHT
The formal grammar is
(>left mcar mcadr)
Where
>LEFT
is the constructor,MCAR
is the value being injected into the coproduct ofMCAR
+MCADR
, and theMCADR
is just the type for the unused right constructor.Example:
(gebgui::visualize (>left so1 gebbool:bool)) (comp (mcase gebbool:true gebbool:not) (>left so1 gebbool:bool))
In the second example, we inject a term with the shape
SO1
(0
1
) into a pair with the shape (SO1
×GEBBOOL:BOOL
), then we useMCASE
to denote a morphism saying.IF
the input is of the shapeSO1
(0
1
), then give us True, otherwise flip the value of the boolean coming in.

The right injection morphism. Takes two
CATOBJ
values. It is the dual ofINJECTLEFT
The formal grammar is
(>right mcar mcadr)
Where
>RIGHT
is the constructor,MCADR
is the value being injected into the coproduct ofMCAR
+MCADR
, and theMCAR
is just the type for the unused left constructor.Example:
(gebgui::visualize (>right so1 gebbool:bool)) (comp (mcase gebbool:true gebbool:not) (>right so1 gebbool:bool))
In the second example, we inject a term with the shape
GEBBOOL:BOOL
into a pair with the shape (SO1
×GEBBOOL:BOOL
), then we useMCASE
to denote a morphism saying.IF
the input is of the shapeSO1
(0
1
), then give us True, otherwise flip the value of the boolean coming in.

The
LEFT
PROJECTION. Takes twoCATMORPH
values. When theLEFT
PROJECTION morphism is then applied, it grabs the left value of a product, with the type of the product being determined by the twoCATMORPH
values given.the formal grammar of a
PROJECTLEFT
is:(<left mcar mcadr)
Where
<LEFT
is the constructor,MCAR
is the left type of the PRODUCT andMCADR
is the right type of the PRODUCT.Example:
(gebgui::visualize (<left gebbool:bool (prod so1 gebbool:bool)))
In this example, we are getting the left
GEBBOOL:BOOL
from a product with the shape

The
RIGHT
PROJECTION. Takes twoCATMORPH
values. When theRIGHT
PROJECTION morphism is then applied, it grabs the right value of a product, with the type of the product being determined by the twoCATMORPH
values given.the formal grammar of a
PROJECTRIGHT
is:(<right mcar mcadr)
Where
<RIGHT
is the constructor,MCAR
is the right type of the PRODUCT andMCADR
is the right type of the PRODUCT.Example:
(gebgui::visualize (comp (<right so1 gebbool:bool) (<right gebbool:bool (prod so1 gebbool:bool))))
In this example, we are getting the right
GEBBOOL:BOOL
from a product with the shape
The Accessors specific to Subst Morph
7.3 Accessors
[in package GEB.UTILS]
These functions are generic lenses of the GEB codebase. If a class is defined, where the names are not known, then these accessors are likely to be used. They may even augment existing classes.

Grabs the underlying object

the name of the given object

the function of the object
[genericfunction] PREDICATE OBJ
the
PREDICATE
of the object

the then branch of the object

the then branch of the object
7.4 Constructors
[in package GEB.SPEC]
The API for creating GEB terms. All the functions and variables here relate to instantiating a term
[variable] *SO0* s0
The Initial Object
[variable] *SO1* s1
The Terminal Object
More Ergonomic API variants for *SO0*
and *SO1*
 [function] MAKEALIAS &KEY NAME OBJ
 [function] HASALIASP OBJ
[function] <LEFT MCAR MCADR
projects left constructor
[function] <RIGHT MCAR MCADR
projects right constructor
[function] >LEFT MCAR MCADR
injects left constructor
[function] >RIGHT MCAR MCADR
injects right constructor
 [function] MCASE MCAR MCADR
 [function] MAKEFUNCTOR &KEY OBJ FUNC
7.5 API
Various forms and structures built ontop of Core Category
7.5.1 Booleans
[in package GEBBOOL]
Here we define out the idea of a boolean. It comes naturally from the concept of coproducts. In ML they often define a boolean like
data Bool = False  True
We likewise define it with coproducts
(def bool (coprod so1 so1))
(def true (>right so1 so1))
(def false (>left so1 so1))
The functions given work on this.

The true value of a boolean type. In this case we've defined true as the right unit

The false value of a boolean type. In this case we've defined true as the left unit

The Boolean Type, composed of a coproduct of two unit objects
(coprod so1 so1)
7.5.2 Translation Functions
[in package GEB.TRANS]
These cover various conversions from Subst Morph and Subst Obj into other categorical data structures.
[genericfunction] TOPOLY MORPHISM
Turns a Subst Morph into a
POLY:POLY
[function] TOCIRCUIT OBJ NAME
Turns a Subst Morph to a VampIR Term
7.5.3 Utility
[in package GEB.MAIN]
Various utility functions ontop of Core Category
[function] PAIRTOLIST PAIR &OPTIONAL ACC
converts excess pairs to a list format
[function] SAMETYPETOLIST PAIR TYPE &OPTIONAL ACC
converts the given type to a list format
[function] CLEAVE V1 &REST VALUES
Applies each morphism to the object in turn.
[function] CONST F X
The constant morphism.
Takes a morphism from
SO1
to a desired value of type $B$, along with a<SUBSTOBJ>
that represents the input type say of type $A$, giving us a morphism from $A$ to $B$.Thus if:
F
:SO1
→ a,X
: bthen: (const f x) : a → b
Γ, f : so1 → b, x : a  (const f x) : a → b
Further, If the input
F
is anALIAS
, then we wrap the output in a new alias to denote it's a constant version of that value.Example:
(const true bool) ; bool > bool
 [function] COMMUTES X Y
[function] COMMUTESLEFT MORPH
swap the input domain of the given catmorph
In order to swap the domain we expect the catmorph to be a
PROD
Thus if:
(dom morph) ≡ (prod x y)
, for anyx
,y
CATOBJ
then:
(commutesleft (dom morph)) ≡ (prod y x)
uΓ, f : x × y → a  (commutesleft f) : y × x → a
 [function] !> A B
 [function] SOEVAL X Y
 [function] SOHOMOBJ X Z
[genericfunction] SOCARDALG OBJ
Gets the cardinality of the given object, returns a
FIXNUM
 [method] SOCARDALG (OBJ <SUBSTOBJ>)

Curries the given object, returns a catmorph
The catmorph given must have its
DOM
be of aPROD
type, asCURRY
invokes the idea ofif f : (
PROD
a b) → cfor all
a
,b
, andc
being an element of catmorphthen: (curry f): a → c^b
where c^b means c to the exponent of b (
EXPT
c b)Γ, f : a × b → c,  (curry f) : a → c^b
In category terms,
a → c^b
is isomorphic toa → b → c
[genericfunction] TEXTNAME MORPH
Gets the name of the moprhism
7.6 Examples
PLACEHOLDER: TO SHOW OTHERS HOW EXAMPLE
s WORK
Let's see the transcript of a real session of someone working with GEB:
(values (princ :hello) (list 1 2))
.. HELLO
=> :HELLO
=> (1 2)
(+ 1 2 3 4)
=> 10
8 The GEB GUI
[in package GEBGUI]
This section covers the suite of tools that help visualize geb objects and make the system nice to work with
8.1 Visualizer
The GEB visualizer deals with visualizing any objects found in the Core Category
if the visualizer gets a Subst Morph, then it will show how
the GEB:SUBSTMORPH
changes any incoming term.
if the visualizer gets a Subst Obj, then it shows the data layout of the term, showing what kind of data
[function] VISUALIZE OBJECT &OPTIONAL (ASYNC
T
)Visualizes both Subst Obj and Subst Morph objects

Kills all threads and open gui objects created by
VISUALIZE
8.1.1 Aiding the Visualizer
One can aid the visualization process a bit, this can be done by
simply playing GEB:ALIAS
around the object, this will place it
in a box with a name to better identify it in the graphing procedure.
8.2 The GEB Graphizer
[in package GEBGUI.GRAPHING]
This section covers the GEB Graph representation
8.2.1 The GEB Graphizer Core
[in package GEBGUI.CORE]
This section covers the graphing procedure in order to turn a GEB object into a format for a graphing backend.
The core types that facilittate the functionality

A note is a note about a new node in the graph or a note about a
NODE
which should be merged into an upcomingNODE
.An example of a
NODENOTE
would be in the case of pair(pair g f)
Π₁ f> Y X > [Y × Z] g> Z Π₂
An example of a MERGENOTE
(Case f g) (COMP g f)
χ₁ > X f [X + Y] > A > Y g/ χ₂ X f> Y > Y g> Z
Notice that in the pair case, we have a note and a shared node to place down, where as in both of the MERGENOTE examples, the Note at the end is not prepended by any special information

I represent a graphical node structure. I contain my children and a value to display, along with the representation for which the node really stands for.
Further, we derive the metamixin, as it's important for arrow drawing to know if we are the left or the right or the nth child of a particular node. This information is tracked, by storing the object that goes to it in the meta table and recovering the note.
 [function] MAKENOTE &REST INITARGS &KEY FROM NOTE VALUE &ALLOWOTHERKEYS
 [function] MAKESQUASH &REST INITARGS &KEY VALUE &ALLOWOTHERKEYS
[genericfunction] GRAPHIZE MORPH NOTES
Turns a morphism into a node graph.
The
NOTES
serve as a way of sharing and continuing computation.If the
NOTE
is a:SHARED
NOTE
then it represents aNODE
without children, along with saying where it came from. This is to be stored in parent of theNOTE
If the
NOTE
is a:CONTINUE
NOTE
, then the computation is continued at the spot.The parent field is to set the note on the parent if the
NOTE
is going to be merged
 [genericfunction] VALUE OBJECT
[function] CONSNOTE NOTE NOTES
Adds a note to the notes list.
[function] APPLYNOTE NOTETOBEON NOTE
Here we apply the
NOTE
to theNODE
.In the case of a new node, we record down the information in the note, and set the note as the child of the current
NODE
. TheNODE
is returned.In the case of a squashnote, we instead just return the squashnote as that is the proper
NODE
to continue from
 [genericfunction] REPRESENTATION OBJECT
 [genericfunction] CHILDREN OBJECT
[function] DETERMINETEXTANDOBJECTFROMNODE FROM TO
Helps lookup the text from the node
[function] NOTERIZECHILDREN NODE FUNC
Applies a specified note to the
CHILDREN
of theNODE
.It does this by applying
FUNC
on all theCHILDREN
and the index of the child in the list
[function] NOTORIZECHILDRENWITHINDEXSCHEMA PREFIX NODE
Notorizes the node with a prefix appended with the subscripted number
8.2.2 The GEB Graphizer Passes
[in package GEBGUI.GRAPHING.PASSES]
This changes how the graph is visualized, simplifying the graph in ways that are intuitive to the user
[function] PASSES NODE
Runs all the passes that simplify viewing the graph. These simplifications should not change the semantics of the graph, only display it in a more bearable way
9 Polynomial Specification
[in package GEB.POLY]
This covers a GEB view of Polynomials. In particular this type will be used in translating GEB's view of Polynomials into Vampir
9.1 Polynomial Types
[in package GEB.POLY.SPEC]
This section covers the types of things one can find in the POLY
constructors

If the
MCAR
argument is strictly less than theMCADR
then theTHEN
branch is taken, otherwise theELSE
branch is taken.
9.2 Polynomial Constructors
[in package GEB.POLY.SPEC]
Every accessor for each of the CLASS
's found here are from Accessors
[function] + MCAR MCADR &REST ARGS
Creates a multiway constructor for +
[function] * MCAR MCADR &REST ARGS
Creates a multiway constructor for *
[function] / MCAR MCADR &REST ARGS
Creates a multiway constructor for /
[function]  MCAR MCADR &REST ARGS
Creates a multiway constructor for 
[function] MOD MCAR MCADR
MOD
ARG1 by ARG2
[function] COMPOSE MCAR MCADR &REST ARGS
Creates a multiway constructor for
COMPOSE
[function] IFZERO PRED THEN ELSE
checks if
PREDICATE
is zero then take theTHEN
branch otherwise theELSE
branch
[function] IFLT MCAR MCADR THEN ELSE
Checks if the
MCAR
is less than theMCADR
and chooses the appropriate branch
9.3 Polynomial Transformations
[in package GEB.POLY.TRANS]
This covers transformation functions from
[genericfunction] TOVAMPIR MORPHISM VALUE
Turns a
POLY
term into a VampIR term with a given value
[function] TOCIRCUIT MORPHISM NAME
Turns a
POLY
term into a VampIR Gate with the given name
10 The Simply Typed Lambda Calculus model
[in package GEB.LAMBDA]
This covers GEB's view on simply typed lambda calculus
10.1 Lambda Specification
[in package GEB.LAMBDA.SPEC]
This covers the various the abstract data type that is the simply typed lambda calculus within GEB.
The specification follows from the sum type declaration
(defunion stlc
(absurd (value t))
unit
(left (value t))
(right (value t))
(caseon (lty geb.spec:substmorph)
(rty geb.spec:substmorph)
(cod geb.spec:substmorph)
(on t) (left t) (right t))
(pair (lty geb.spec:substmorph) (rty geb.spec:substmorph) (left t) (right t))
(fst (lty geb.spec:substmorph) (rty geb.spec:substmorph) (value t))
(snd (lty geb.spec:substmorph) (rty geb.spec:substmorph) (value t))
(lamb (vty geb.spec:substmorph) (tty geb.spec:substmorph) (value t))
(app (dom geb.spec:substmorph) (cod geb.spec:substmorph) (func t) (obj t))
(index (index fixnum)))
 [type] <STLC>
 [type] ABSURD
 [function] ABSURDVALUE INSTANCE
 [type] UNIT
 [type] PAIR
 [function] PAIRLTY INSTANCE
 [function] PAIRRTY INSTANCE
 [function] PAIRLEFT INSTANCE
 [function] PAIRRIGHT INSTANCE
 [type] LEFT
 [function] LEFTVALUE INSTANCE
 [type] RIGHT
 [function] RIGHTVALUE INSTANCE
 [type] CASEON
 [function] CASEONLTY INSTANCE
 [function] CASEONRTY INSTANCE
 [function] CASEONCOD INSTANCE
 [function] CASEONON INSTANCE
 [function] CASEONLEFT INSTANCE
 [function] CASEONRIGHT INSTANCE
 [type] FST
 [function] FSTLTY INSTANCE
 [function] FSTRTY INSTANCE
 [function] FSTVALUE INSTANCE
 [type] SND
 [function] SNDLTY INSTANCE
 [function] SNDRTY INSTANCE
 [function] SNDVALUE INSTANCE
 [type] LAMB
 [function] LAMBVTY INSTANCE
 [function] LAMBTTY INSTANCE
 [function] LAMBVALUE INSTANCE
 [type] APP
 [function] APPDOM INSTANCE
 [function] APPCOD INSTANCE
 [function] APPFUNC INSTANCE
 [function] APPOBJ INSTANCE
 [type] INDEX
 [function] INDEXINDEX INSTANCE
[function] TYPED V TYP
Puts together the type declaration with the value itself for lambda terms
 [function] TYPEDSTLCTYPE INSTANCE
 [function] TYPEDSTLCVALUE INSTANCE
10.2 Main functionality
[in package GEB.LAMBDA.MAIN]
This covers the main API for the STLC
module
10.3 Transition Functions
[in package GEB.LAMBDA.TRANS]
These functions deal with transforming the data structure to other data types
[genericfunction] COMPILECHECKEDTERM CONTEXT TYPE TERM
Compiles a checked term into SubstMorph category
 [function] TOPOLY CONTEXT TYPE OBJ
 [function] TOCIRCUIT CONTEXT TYPE OBJ NAME
10.3.1 Utility Functionality
These are utility functions relating to translating lambda terms to other types
[function] STLCCTXTOMU CONTEXT
Converts a generic (CODE
) context into aSUBSTMORPH
[function] SOHOM DOM COD
Computes the homobject of two
SUBSTMORPH
s
11 Mixins
[in package GEB.MIXINS]
Various mixins of the project. Overall all these offer various services to the rest of the project
11.1 Pointwise Mixins
Here we provide various mixins that deal with classes in a pointwise
manner. Normally, objects can not be compared in a pointwise manner,
instead instances are compared. This makes functional idioms like
updating a slot in a pure manner (allocating a new object), or even
checking if two objects are EQUAL
able adhoc. The pointwise API,
however, derives the behavior and naturally allows such idioms

Provides the service of giving point wise operations to classes
Further we may wish to hide any values inherited from our superclass due to this we can instead compare only the slots defined directly in our class
[class] DIRECTPOINTWISEMIXIN POINTWISEMIXIN
Works like
POINTWISEMIXIN
, however functions onPOINTWISEMIXIN
will only operate on directslots instead of all slots the class may contain.Further all
DIRECTPOINTWISEMIXIN
's arePOINTWISEMIXIN
's
11.2 Pointwise API
These are the general API functions on any class that have the
POINTWISEMIXIN
service.
Functions like TOPOINTWISELIST
allow generic list traversal APIs to
be built off the keyvalue pair of the raw object form, while
OBJEQUALP
allows the checking of functional equality between
objects. Overall the API is focused on allowing more generic
operations on classes that make them as useful for generic data
traversal as LIST
(0
1
)'s are
[genericfunction] TOPOINTWISELIST OBJ
Turns a given object into a pointwise
LIST
(0
1
). listing theKEYWORD
slotname next to their value.
[genericfunction] OBJEQUALP OBJECT1 OBJECT2
Compares objects with pointwise equality. This is a much weaker form of equality comparison than
STANDARDOBJECT
EQUALP
, which does the much stronger pointer quality
[genericfunction] POINTWISESLOTS OBJ
Works like
C2MOP:COMPUTESLOTS
however on the object rather than the class
11.3 Mixins Examples
Let's see some example uses of POINTWISEMIXIN
:
(objequalp (geb:terminal geb:so1)
(geb:terminal geb:so1))
=> t
(topointwiselist (geb:coprod geb:so1 geb:so1))
=> ((:MCAR . s1) (:MCADR . s1))
11.4 Metadata Mixin
Metadata is a form of meta information about a particular object. Having metadata about an object may be useful if the goal requires annotating some data with type information, identification information, or even various levels of compiler information. The possibilities are endless and are a standard technique.
For this task we offer the METAMIXIN
which will allow
metadata to be stored for any type that uses its service.

Use my service if you want to have metadata capabilities associated with the given object. Performance covers my performance characteristics
For working with the structure it is best to have operations to treat it like an ordinary hashtable
[function] METAINSERT OBJECT KEY VALUE &KEY WEAK
Inserts a value into storage. If the key is a one time object, then the insertion is considered to be volatile, which can be reclaimed when no more references to the data exists.
If the data is however a constant like a string, then the insertion is considered to be long lived and will always be accessible
The :weak keyword specifies if the pointer stored in the value is weak
[function] METALOOKUP OBJECT KEY
Lookups the requested key in the metadata table of the object. We look past weak pointers if they exist
11.4.1 Performance
The data stored is at the CLASS
level. So having your type take the
METAMIXIN
does interfere with the cache.
Due to concerns about meta information being populated over time, the table which it is stored with is in a weak hashtable, so if the object that the metadata is about gets deallocated, so does the metadata table.
The full layout can be observed from this interaction
;; any class that uses the service
(defparameter *x* (makeinstance 'metamixin))
(metainsert *x* :a 3)
(defparameter *y* (makeinstance 'metamixin))
(metainsert *y* :b 3)
(defparameter *z* (makeinstance 'metamixin))
;; where {} is a hashtable
{*x* {:a 3}
*y* {:b 3}}
Since *z*
does not interact with storage no overhead of storage is
had. Further if `x goes out of scope, gc would reclaim the table leaving
{*y* {:b 3}}
for the hashtable.
Even the tables inside each object's map are weak, thus we can make storage inside metadata be separated into volatile and stable storage.
12 Geb Utilities
[in package GEB.UTILS]
The Utilities package provides general utility functionality that is used throughout the GEB codebase

Allows us to state a list contains a given type.
NOTE
This does not type check the whole list, but only the first element. This is an issue with how lists are defined in the language. Thus this should be be used for intent purposes.
For a more proper version that checks all elements please look at writing code like
(deftype normalformlist () `(satisfies normalformlist)) (defun normalformlist (list) (and (listp list) (every (lambda (x) (typep x 'normalform)) list))) (deftype normalform () `(or wire constant))
Example usage of this can be used with
typep
(typep '(1 . 23) '(listof fixnum)) => NIL (typep '(1 23) '(listof fixnum)) => T (typep '(1 3 4 "hi" 23) '(listof fixnum)) => T (typep '(1 23 . 5) '(listof fixnum)) => T
Further this can be used in type signatures
(> foo (fixnum) (listof fixnum)) (defun foo (x) (list x))
[function] SYMBOLTOKEYWORD SYMBOL
[macro] MUFFLEPACKAGEVARIANCE &REST PACKAGEDECLARATIONS
Muffle any errors about package variance and stating exports out of order. This is particularly an issue for SBCL as it will error when using MGLPAX to do the export instead of
DEFPACKAGE
.This is more modular thank MGLPAX:DEFINEPACKAGE in that this can be used with any package creation function like UIOP:DEFINEPACKAGE.
Here is an example usage:
(geb.utils:mufflepackagevariance (uiop:definepackage #:geb.lambda.trans (:mix #:trivia #:geb #:serapeum #:commonlisp) (:export :compilecheckedterm :stlcctxtomu)))
[function] SUBCLASSRESPONSIBILITY OBJ
Denotes that the given method is the subclasses responsibility. Inspired from Smalltalk
 [function] SHALLOWCOPYOBJECT ORIGINAL
[macro] MAKEPATTERN OBJECTNAME &REST CONSTRUCTORNAMES
make pattern matching position style instead of record style. This removes the record constructor style, however it can be brought back if wanted
(defclass alias (<substmorph> <substobj>) ((name :initarg :name :accessor name :type symbol :documentation "The name of the GEB object") (obj :initarg :obj :accessor obj :documentation "The underlying geb object")) (:documentation "an alias for a geb object")) (makepattern alias name obj)
[function] NUMBERTODIGITS NUMBER &OPTIONAL REM
turns an
INTEGER
into a list of its digits
[function] DIGITTOUNDER DIGIT
Turns a digit into a subscript string version of the number
[function] NUMBERTOUNDER INDEX
12.1 Accessors
These functions are generic lenses of the GEB codebase. If a class is defined, where the names are not known, then these accessors are likely to be used. They may even augment existing classes.

Grabs the underlying object

the name of the given object

the function of the object
[genericfunction] PREDICATE OBJ
the
PREDICATE
of the object

the then branch of the object

the then branch of the object
13 Testing
[in package GEBTEST]
We use parachute as our testing framework.
Please read the manual for extra features and how to better lay out future tests
[function] RUNTESTS &KEY (INTERACTIVE?
NIL
) (SUMMARY?NIL
) (PLAIN?T
) (DESIGNATORS '(GEBTESTSUITE
))Here we run all the tests. We have many flags to determine how the tests ought to work
(runtests :plain? nil :interactive? t) ==> 'interactive (runtests :summary? t :interactive? t) ==> 'noisysummary (runtests :interactive? t) ==> 'noisyinteractive (runtests :summary? t) ==> 'summary (runtests) ==> 'plain (runtests :designators '(geb geb.lambda)) ==> run only those packages
[function] CODECOVERAGE &OPTIONAL (PATH
NIL
)generates code coverage, for CCL the coverage can be found at
simply run this function to generate a fresh one