blog/posts-wip/2023-10-25-quox.md.old

178 lines
6.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: quox. the language
date: 2023-10-25
tags: [quox, computer, types]
bibliography: quox.bib
link-citations: true
show-toc: true
...
<style>
header h1 { margin-left: 0; }
header h1::before, header h1::after {
content: url(../images/qt.svg);
display: inline-block;
height: 0.75em; width: 0.75em;
padding: 0 0.5em;
}
header h1::before {
transform: rotateY(0.5turn);
}
main > :is(h1, h2, h3, h4, h5, h6)::after {
content: url(../images/quox-tod.png);
image-rendering: crisp-edges;
image-rendering: pixelated;
margin-left: 0.5em;
}
.qtt-q { font-family: Muller; font-weight: 600; color: #60c; }
.xtt-x { font-family: Muller; font-weight: 600; color: #082; }
#panqt {
--width: 202px; --height: 200px;
}
#panqt div {
width: var(--width); height: var(--height);
position: relative;
}
#panqt img, #panqt div::before {
position: absolute;
top: 0; left: 0;
width: var(--width); height: var(--height);
}
#panqt div::before {
content:
image-set(url(../images/panqt.png) 1x,
url(../images/panqt2x.png) 2x);
mix-blend-mode: multiply;
}
#panqt figcaption {
width: var(--width);
}
</style>
:::{.aside .floating}
### [hot minute](https://en.wiktionary.org/wiki/hot_minute)&ensp;<i>n.</i> {.unnumbered}
1. A long period of time.
2. A short period of time.
3. An unspecified period of time.
:::
for the last _hot minute_ [@hotminute], ive been working on a little programming language. its finally starting to approach a state where it can compile some programs, so maybe i should talk about it a bit.
# what is a quox [(tl;dr for type system nerds)]{.note}
<figure class=floating>
<img src=../images/quox.png class='shadow pixel'
alt='a dragon from an old arcade game'
title='use my warps to skip some floors!'>
<figcaption>this is also a quox.</figcaption>
</figure>
0. its a *dependently typed functional language*, like your agdas and your idrises.
1. it has a *closed type universe*. you dont define new datatypes, but the language gives you building blocks to put them together.
2. *[q]{.qtt-q}uantitative type theory* (qtt) [@nuttin; @qtt] is a nice combination of dependent types, resource tracking, and erasure of stuff like proofs.
3. *[x]{.xtt-x}tt* [@xtt], which `*i sure hope i remember to come back and add this!*`
- the closed type universe is a consequence of xtt (as well as its kinda-predecessor ott [@ott-now]), but i decided to just run with it.
- “xtt” stands for “extensional type theory”, but its not _that_ extensional type theory. i know. not my fault.
so now you can see where the name [q]{.qtt-q}uo[x]{.xtt-x} comes from. other than my favourite dragon. anyway it also has
<figure class=floating id=panqt>
<div><img src=../images/panqt.nobg.png srcset='../images/panqt.nobg2x.png 2x'
width=202 height=200
alt='one of my fursonas is a quox with three heads'
title='i hear putting pictures of your fursona on your blog is a good way to get hacker news types Big Mad if they find out about it'></div>
<figcaption>
sometimes i am also a quox. or three, depending on how you count.
</figcaption>
</figure>
4. *bidirectional type checking* [@bidi] `*this one too*`
5. crude-but-effective stratification [@crude; @crude-blog] for dealing with universes. `*does this need more detail too?*`
6. *written in idris2*. that doesnt really have much impact on the language itself, other than the compilation process, but im enjoying using a dependently typed language for something substantial. even if its one youre not currently supposed to be using for anything substantial. also currently it spits out scheme, like idris, because that was easy.
7. all the non-ascii syntax is [optional], but i like it.
[optional]: https://git.rhiannon.website/rhi/quox/wiki/ascii-syntax
as for what it _doesnt_ have: any but the most basic of conveniences. sorry.
# dependent types
there are lots of languages with dependent types—well, quite a few—so i wont spend too much time on this.
`*but still something*`
# closed type universe
instead of having datatypes like in normal languages, in quox you get the basic building blocks to make them. the main building blocks are functions, pairs, enumerations, equality types, strings, and natural numbers. some sort of syntactic sugar to expand a datatype declaration into this representation _is_ something i want to add, but it'd be in the pretty distant future.
:::aside
_at the moment_, natural numbers are the only recursion possible. so you can define types with the same recursive structure, like lists, but binary trees and stuff are not _currently_ possible, until i replace them with something more general. probably w-types [@nlab-wtype].
:::
but right now you can define a few types like this. see [qtt](#qtt) below for what all the `0`s and `ω`s mean. due to the lack of generic recursion, but the presence of _natural numbers_ specifically, a list is a length, followed by a nested tuple of that length (terminated by `'nil`).
```quox
def0 Vec : → ★ → ★ =
λ n A ⇒
case n return ★ of {
zero ⇒ {nil};
succ p, As ⇒ A × As
} -- ↖ As = Vec p A
def0 List : ★ → ★ = λ A ⇒ (n : ) × Vec n A
def Nil : 0.(A : ★) → List A = λ A ⇒ (0, 'nil)
def Cons : 0.(A : ★) → A → List A → List A =
λ A x xs ⇒ case xs return List A of { (len, xs) ⇒ (succ len, x, xs) }
def NilS = Nil String
def ConsS = Cons String
def example = ConsS "im" (ConsS "gay" NilS)
def0 example-eq : example ≡ (2, "im", "gay", 'nil) : List String =
refl (List String) example
```
you might have noticed that i didn't write the eliminator. that is because they are kind of ugly. if you want to see it anyway you can find it in [the example folder][ex].
[ex]: https://git.rhiannon.website/rhi/quox/src/commit/246d80eea2/examples/list.quox#L12-L25
# qtt
sometimes, values of some type can only be used in certain ways to make sense. this is hardly controversial; if you do this with
a problem that dependent types used to have a lot is that the blurring of compile-time and run-time data can lead to more being retained than necessary.
`*is there an example that has superlinear junk data without resorting to peano naturals or some shit*`
consider this vector (length-indexed list) definition from a _hypothetical language_ with normal inductive types.
```agda
data Vect (A : ★) : → ★ where
[] : Vect A 0
_∷_ : (n : ) → A → Vect A n → Vect A (succ n)
```
in a totally naive implementation, `cons` would store `n`, the length of its tail (and maybe even some kind of representation of `A` too). so a three element list would look something like
# xtt
`*mention about type-case and the closed universe*`
# bidirectional type checking
# references {#refs}