Conversation

[Type Theory; C++] Hey type theorists, Do any of you know good reading materials on dependent functions? Notably anything on ideas of composition, forming an algebra? My application of interest is C++. Backstory: Over the years I've had the most success with C++ by 1/10
3
2
loosely translating C++ grammar into formal type theory. Granted C++ has its own type system, but because it's incrementally designed by a community it's ad hoc and kind of all over the place. Right now I'm adding a *generics* module to my personal library and version 1.0 2/10
1
worked but was messy: The style is *dispatch by spec* but all the translation work done under the hood was packaged together and ended up being spaghetti code. I've been redesigning and slowly pulling out subroutines from that spaghetti into meaningful, reusable modules. 3/10
1
This is where dependent functions come in. To review (for those readers who don't fully know), to arrive at a dependent function as an idea think of it like this: We start with a regular function: f : A --> B Notice the domain and range (codomain) are predefined? 4/10
1
We generalize this idea by weakening this constraint: f(x) : A --> B[x] which is to say we still predefine the domain, but now the range (codomain) is ***dependent*** on the input value. We compute the output in two rounds. Round one we take 'x' and figure out B[x], 5/10
1
then in round two we figure out the output because we at least now know which type the output is even a part of. C++ comes in because the grammar that's most similar to dependent functions is *templated functions*: template<auto x> B<x> f(A v) { return /*insert code*/; } 6/10
2
In this example, how do you ensure that `x` and `v` are the same input? Is it right to assume that you are translating from something like this: λx. ? : (x : A) → B x …where `?` is the stuff in `/*insert code*/`?
2
Mostly for me in terms of C++ I'm less picky about which grammar is *meant* to be interpreted as a "function". For example: [see image] A variable template can be interpreted as a compile time function (eg. dependent_f<int> returns square<int>). That's why I value theory more.
Image
2
Show replies