<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Using Pie on Massimo Nocentini</title><link>https://massimo-nocentini.github.io/book/dependent-types/part-1/</link><description>Recent content in Using Pie on Massimo Nocentini</description><generator>Hugo</generator><language>en-US</language><atom:link href="https://massimo-nocentini.github.io/book/dependent-types/part-1/index.xml" rel="self" type="application/rss+xml"/><item><title>Types that mention values</title><link>https://massimo-nocentini.github.io/book/dependent-types/part-1/01-intro/</link><dc:creator>Massimo Nocentini</dc:creator><guid>https://massimo-nocentini.github.io/book/dependent-types/part-1/01-intro/</guid><description>&lt;p&gt;Pie is the small dependently typed language that accompanies &lt;em&gt;The Little Typer&lt;/em&gt;&lt;label for="sn-4c30c8-1" class="margin-toggle sidenote-number"&gt;&lt;/label&gt;&lt;input type="checkbox" id="sn-4c30c8-1" class="margin-toggle"/&gt;&lt;span class="sidenote citation"&gt;&lt;span class="bib-entry" data-cite="littletyper"&gt;Daniel P. Friedman and David Thrane Christiansen. &lt;cite&gt;The Little Typer&lt;/cite&gt;. MIT Press, Cambridge, MA, 2018&lt;/span&gt;&lt;/span&gt;. In the terms of type theory it is a small intensional Martin-Löf type theory&lt;label for="sn-4c30c8-2" class="margin-toggle sidenote-number"&gt;&lt;/label&gt;&lt;input type="checkbox" id="sn-4c30c8-2" class="margin-toggle"/&gt;&lt;span class="sidenote citation"&gt;&lt;span class="bib-entry" data-cite="martinlof1975"&gt;Per Martin-Löf. An Intuitionistic Theory of Types: Predicative Part. In H. E. Rose and J. C. Shepherdson, editors, &lt;cite&gt;Logic Colloquium ’73&lt;/cite&gt;, volume 80 of &lt;cite&gt;Studies in Logic and the Foundations of Mathematics&lt;/cite&gt;, pages 73–118. North-Holland, Amsterdam, 1975&lt;/span&gt;; and &lt;span class="bib-entry" data-cite="martinlof1984"&gt;Per Martin-Löf. &lt;cite&gt;Intuitionistic Type Theory&lt;/cite&gt;. Bibliopolis, Naples, 1984. Notes by Giovanni Sambin&lt;/span&gt;&lt;/span&gt;: dependent functions and pairs, natural numbers, atoms, lists, vectors, sums, an identity type, the empty and unit types and a single universe, all built in, with no way to declare more (&lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-3/10-context/"&gt;Chapter&amp;nbsp;10&lt;/a&gt; lists what it leaves out). Its implementation is a Racket package of about 6700 lines, counting the top-level &lt;code&gt;.rkt&lt;/code&gt; files and the language reference &lt;code&gt;pie.scrbl&lt;/code&gt; (&lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-1/01-intro/#tab-files"&gt;Table&amp;nbsp;1.1&lt;/a&gt;). We read it side by side with Pie programs that we run, assuming that the reader knows Scheme (closures, environments, an eval/apply interpreter) and miniKanren (relations, modes, unification) but not dependent types.&lt;/p&gt;</description></item><item><title>Programming with a fixed menu of types</title><link>https://massimo-nocentini.github.io/book/dependent-types/part-1/02-programs/</link><dc:creator>Massimo Nocentini</dc:creator><guid>https://massimo-nocentini.github.io/book/dependent-types/part-1/02-programs/</guid><description>&lt;p&gt;Pie has no way to declare a new datatype. It offers a fixed menu of types, collected in &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-1/02-programs/#tab-types"&gt;Table&amp;nbsp;2.1&lt;/a&gt;. Here we use the menu as a programmer would, building values, taking them apart and reading what Pie prints. Two facts met here shape everything else. An expression can get &lt;em&gt;stuck&lt;/em&gt; on a variable that has no value, and a definition cannot call itself.&lt;/p&gt;&#10;&lt;figure class="fullwidth tufte-table"&gt;&lt;div class="table-wrapper fullwidth"&gt;&#10;&lt;table class="fullwidth"&gt;&#10;&lt;thead&gt;&#10;&lt;tr&gt;&#10;&lt;th style="text-align: left"&gt;Type&lt;/th&gt;&#10;&lt;th style="text-align: left"&gt;Formation&lt;/th&gt;&#10;&lt;th style="text-align: left"&gt;Constructors&lt;/th&gt;&#10;&lt;th style="text-align: left"&gt;Eliminators&lt;/th&gt;&#10;&lt;th style="text-align: left"&gt;ι-rules&lt;/th&gt;&#10;&lt;th style="text-align: left"&gt;η&lt;/th&gt;&#10;&lt;/tr&gt;&#10;&lt;/thead&gt;&#10;&lt;tbody&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;U&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;is-type 96; not in &lt;code&gt;U&lt;/code&gt; (synth 206–208)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;the types below (synth, in &lt;code&gt;U&lt;/code&gt;)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;none&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;—&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;—&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Nat&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;97 / 205&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;zero&lt;/code&gt; 246, &lt;code&gt;add1&lt;/code&gt; 247–249, numerals 639–647 (all synth)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;which-Nat&lt;/code&gt; 250–261, &lt;code&gt;iter-Nat&lt;/code&gt; 262–274, &lt;code&gt;rec-Nat&lt;/code&gt; 275–289, &lt;code&gt;ind-Nat&lt;/code&gt; 290–303&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;120–181&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;no&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Atom&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;132–133 / 304&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;'a&lt;/code&gt; 352–355 (synth)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;none&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;—&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;no&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Π&lt;/code&gt;, &lt;code&gt;→&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;98–131 / 209–245&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;λ&lt;/code&gt; 663–684 (check)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;application 599–629&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;110–118&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;yes&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Σ&lt;/code&gt;, &lt;code&gt;Pair&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;134–159 / 305–333&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;cons&lt;/code&gt; 685–697 (check)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;car&lt;/code&gt;, &lt;code&gt;cdr&lt;/code&gt; 334–351&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;183–197&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;yes&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;List&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;161–163 / 408–410&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;nil&lt;/code&gt; 698–705 (check), &lt;code&gt;::&lt;/code&gt; 411–414 (synth)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;ind-List&lt;/code&gt; 360–386, &lt;code&gt;rec-List&lt;/code&gt; 387–407&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;199–236&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;no&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Vec&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;171–174 / 502–505&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;vecnil&lt;/code&gt; 718–732, &lt;code&gt;vec::&lt;/code&gt; 733–747 (check)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;head&lt;/code&gt; 506–521, &lt;code&gt;tail&lt;/code&gt; 522–538, &lt;code&gt;ind-Vec&lt;/code&gt; 539–572&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;308–359&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;length &lt;code&gt;zero&lt;/code&gt; only&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Either&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;175–178 / 573–576&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;left&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt; 748–767 (check)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;ind-Either&lt;/code&gt; 577–590&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;361–378&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;no&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;165–170 / 421–426&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;same&lt;/code&gt; 706–717 (check)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;replace&lt;/code&gt; 427–444, &lt;code&gt;trans&lt;/code&gt; 445–458, &lt;code&gt;cong&lt;/code&gt; 459–475, &lt;code&gt;symm&lt;/code&gt; 476–484, &lt;code&gt;ind-=&lt;/code&gt; 485–501&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;245–306&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;no&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Trivial&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;160 / 356–357&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;sole&lt;/code&gt; 358–359 (synth)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;none&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;—&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;yes&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;tr&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;Absurd&lt;/code&gt;&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;164 / 415–416&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;none&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;&lt;code&gt;ind-Absurd&lt;/code&gt; 417–420&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;never reduces (238–243)&lt;/td&gt;&#10;&lt;td style="text-align: left"&gt;yes&lt;/td&gt;&#10;&lt;/tr&gt;&#10;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&lt;figcaption class="caption-margin"&gt;&lt;span class="caption-label"&gt;Table&amp;nbsp;&lt;span class="tufte-num" data-kind="table" data-key="tab-types" data-labeled="1"&gt;2.1&lt;/span&gt;:&lt;/span&gt; &lt;span class="caption-text"&gt;Pie&amp;rsquo;s fixed menu of types. Line numbers in the Formation, Constructors and Eliminators columns are in &lt;code&gt;typechecker.rkt&lt;/code&gt;; in a pair of ranges separated by a slash, the first is the clause of &lt;code&gt;is-type&lt;/code&gt; (the type is a type) and the second the clause of &lt;code&gt;synth&lt;/code&gt; (the type is an element of &lt;code&gt;U&lt;/code&gt;). “check” and “synth” say whether a constructor only checks against a given type or also synthesizes its own. The ι-rules column gives the &lt;code&gt;do-*&lt;/code&gt; functions in &lt;code&gt;normalize.rkt&lt;/code&gt;. The η column says whether read-back has an η-rule for the type; &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-3/08-nbe/#tab-eta"&gt;Table&amp;nbsp;8.2&lt;/a&gt; in &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-3/08-nbe/"&gt;Chapter&amp;nbsp;8&lt;/a&gt; lists them. On a first reading the Type, Constructors and Eliminators columns are enough: &lt;code&gt;is-type&lt;/code&gt; and &lt;code&gt;synth&lt;/code&gt; are explained in &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-3/09-checking/"&gt;Chapter&amp;nbsp;9&lt;/a&gt;, the ι- and η-rules in &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-3/08-nbe/"&gt;Chapter&amp;nbsp;8&lt;/a&gt;.&lt;/span&gt;&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p&gt;An atom is a quoted name, of type &lt;code&gt;Atom&lt;/code&gt;. A natural number is &lt;code&gt;zero&lt;/code&gt; or &lt;code&gt;(add1 n)&lt;/code&gt;, of type &lt;code&gt;Nat&lt;/code&gt;. Each top-level expression is printed as &lt;code&gt;(the T e)&lt;/code&gt;, its type and its normal form (&lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-1/01-intro/#sub:intro-running"&gt;Section&amp;nbsp;1.2&lt;/a&gt;). The program &lt;code&gt;atoms.pie&lt;/code&gt; and its output:&lt;/p&gt;</description></item><item><title>Motives, induction and indexed families</title><link>https://massimo-nocentini.github.io/book/dependent-types/part-1/03-motives/</link><dc:creator>Massimo Nocentini</dc:creator><guid>https://massimo-nocentini.github.io/book/dependent-types/part-1/03-motives/</guid><description>&lt;p&gt;The eliminators of &lt;a class="xref" href="https://massimo-nocentini.github.io/book/dependent-types/part-1/02-programs/#sub:programs-nat-elims"&gt;Section&amp;nbsp;2.3&lt;/a&gt; have one fixed result type. In &lt;code&gt;(iter-Nat t b s)&lt;/code&gt; the checker synthesizes a type &lt;span class="katex tufte-math-euler"&gt;&lt;span class="katex-mathml"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding="application/x-tex"&gt;B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; for the base &lt;code&gt;b&lt;/code&gt;, and &lt;span class="katex tufte-math-euler"&gt;&lt;span class="katex-mathml"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding="application/x-tex"&gt;B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt; is then the type of the whole expression, for every target. A dependent eliminator lifts this restriction: the type of the result may depend on the value of the target. The eliminator gets this type from an extra argument, the &lt;em&gt;motive&lt;/em&gt;. This section shows how the motive determines the types of the base and the step, where Pie allows a type to be computed by recursion, and how &lt;code&gt;Vec&lt;/code&gt; uses a natural number as an index that the checker computes while checking. In the rule below, typewriter letters such as &lt;code&gt;t&lt;/code&gt;, &lt;code&gt;mot&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt; and &lt;code&gt;s&lt;/code&gt; stand for expressions, as in the appendix of &lt;em&gt;The Little Typer&lt;/em&gt;&lt;label for="sn-5ef64d-1" class="margin-toggle sidenote-number"&gt;&lt;/label&gt;&lt;input type="checkbox" id="sn-5ef64d-1" class="margin-toggle"/&gt;&lt;span class="sidenote citation"&gt;&lt;span class="bib-entry" data-cite="littletyper"&gt;Daniel P. Friedman and David Thrane Christiansen. &lt;cite&gt;The Little Typer&lt;/cite&gt;. MIT Press, Cambridge, MA, 2018&lt;/span&gt;&lt;/span&gt;, and the elaborated Core output (&lt;span class="tufte-nobr"&gt;&lt;span class="katex tufte-math-euler"&gt;&lt;span class="katex-mathml"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo&gt;⇝&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding="application/x-tex"&gt;\rightsquigarrow c&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt; of the judgment is left out.&lt;/p&gt;</description></item></channel></rss>