-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functor/algebra iteration to Geb external API #62
Comments
The existence of the injections doesn't actually solve the problem completely, because they can go only one way. When we have a Juvix function, e.g.: f : List Nat -> List Nat
f xs := 1 :: 2 :: xs then after compilation to GEB it needs to have type f : List^n Nat -> List^{n+2} Nat for some n. The List type is translated to: type List^n A :=
| nil : List^n A
| :: : A -> List^n A -> List^{n+1} A (we are essentially adding size upper bound annotations). Thus we cannot just globally change every occurrence of the List type to List^N for some maximum N. In general, this seems to leave us with two options:
The first option seems prohibitive in terms of the efficiency of the generated VampIR code / circuit size, but in practice it might be just good enough with reachability analysis (filtering out the definitions not reachable from the main function) or generating (at compile time) the truncations "on demand". Note that we still need injections which are (almost) "free" (in terms of "execution" time / circuit size), because we need to cast things to the common upper bound. For example: f : List Nat -> List Nat
f nil := nil;
f (x :: xs) := if (x = 0) xs (x :: xs) would be converted to f : List^n Nat -> List^n Nat
f nil := nil
f (x :: xs) := if (x = 0) (inject xs) (x :: xs) |
Besides an essentially untyped API, would a dependently typed API ( |
Sorry, didn't notice your comment. The problem is that you can't, in general, go from e.g. List^{n+1} to List^n without doing some runtime check whether the list is short enough. Dependent types don't seem to help here. The problem essentially stems from the fact that we're forced to translate non-dependently typed programs and data structures into dependently typed ones, regardless whether this dependency is explicitly in the API or not (we have different versions of List^n for each n). |
GEB 0.3.2 introduces the following changes. * The STLC frontend no longer requires full type information in terms. The syntax of the terms changed. * An error node has been introduced which allows to compile Juvix `fail` nodes. The following features required for compilation from Juvix are still missing in GEB. * Modular arithmetic types ([GEB issue #61](anoma/geb#61)). * Functor/algebra iteration to implement bounded inductive types ([GEB issue #62](anoma/geb#62)).
Geb is designed internally for its recursive types to be (co)limits of (compositional) powers of polynomial functors, and it should expose an interface to clients to allow objects to be specified as
n
-fold compositional powers of polynomial functors, and hom-objects as algebras of polynomial functors.The idea is that the combination of a polynomial functor
f
, an objecta
, a non-zero natural numbern
, and an algebraf a -> a
allow a type to be defined with (aside from the addition of the fixedn
) the same signature as a recursive one (the recursive type in this case would be the object component of the initial algebraMu(f)
off
, whichf
, as a polynomial endofunctor, is guaranteed to have), and a function with the same signature as a recursive one (where the algebra of typef a -> a
is the function that would be passed to the catamorphism which serves as the elimination rule forMu(f)
, but actually producing a type with a finite number of terms, and non-recursive function with signaturef^n -> a
, which can be executed on a polynomial circuit.Specifically:
poly
(or something) on the categorysubstobj
/substmorph
. It will have the same constructors assubstobj
plus one more:homf
, the covariant hom-functor, which takes asubstobj
parameter. (All the constructors ofsubstobj
apply because the category of polynomial endofunctors also has all finite products and coproducts.)poly
.iterf
, which will take apoly
and a natural number, and produce then
th iteration of the functor (f^0
is the identity, which ishomf so1
;f^1
isf
;f^2
isf . f
, etc.).There will be an operator
apply
which takes apoly
and asubstobj
and applies the (object component of the) endofunctor to the object (producing another object).There will be an operator
map
which takes apoly
and a morphism and applies the (morphism component of the) endofunctor to the morphism (producing another morphism).There will be an alias
alg
which takes apoly
and asubstobj
, and it produces the type of algebras: specifically,alg f a
ishom(f(a), a)
.Finally, there will be a bounded-depth "catamorphism", called something like
catan
: for eachf : poly
,n : Nat
,a : substobj
, andm : alg f a
(som
is a morphism fromf a
toa
),catan f n a m
will produce a morphism fromf^n(so0)
(then
th iteration off
starting with the initial object of thesubst
category) toa
. This is the interface that produces a function resembling a catamorphism fromMu(f)
toa
, but for bounded-depth data structures.Edit: @lukaszcz pointed out that there's something missing from the above. It's supposed to be a finite prefix of a directed colimit, but the "directed" part means that there are injections
f^n -> f ^ (S n)
, which I forgot to specify. Those should exist, as well as a convenience interface that composes an arbitrary number of them to producef^n -> f^m
for anyn < m
.The text was updated successfully, but these errors were encountered: