Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RocqのProgram機構の紹介 〜型を活用した安全なプログラミング〜

RocqのProgram機構の紹介 〜型を活用した安全なプログラミング〜

関数型まつり2025で発表した際のスライドです。
プロポーザルはこちら:https://fortee.jp/2025fp-matsuri/proposal/983d1021-3636-4778-be58-149f1995e8a5

Avatar for Hiroki Tokunaga

Hiroki Tokunaga

July 16, 2025
Tweet

More Decks by Hiroki Tokunaga

Other Decks in Programming

Transcript

  1. でも、idxがリストの長さより短いって分かってたら? nth_safe : forall A : Type, (l : list

    A) -> (idx : nat) -> (hn : idx < length l) -> A 6 証明が必要になる → タクティクスを使いたい
  2. コード例:nth_safe(関数定義) Program Fixpoint nth_safe {A} (l : list A) (idx

    : nat) (hn : idx < length l) : A := match l with | [] => _ | h :: t => match idx with | O => h | S idx' => nth_safe t idx' _ end end. 8
  3. コード例:nth_safe(関数定義) Program Fixpoint nth_safe {A} (l : list A) (idx

    : nat) (hn : idx < length l) : A := match l with | [] => _ | h :: t => match idx with | O => h | S idx' => nth_safe t idx' _ end end. 10 l = []なので hn : idx < length []
  4. コード例:nth_safe(Obligationの解決2) Next Obligation. 12 1 goal A : Type idx'

    : nat h : A t : list A hn : S idx' < length (h :: t) --- idx' < length t
  5. コード例:nth_safe(関数定義) Program Fixpoint nth_safe {A} (l : list A) (idx

    : nat) (hn : idx < length l) : A := match l with | [] => _ | h :: t => match idx with | O => h | S idx' => nth_safe t idx' _ end end. 13 l = h :: t, idx = S idx'なので hn: S idx' < length (h :: t) ゴール:idx' < length t
  6. まとめ - 条件付きの定義を自然に書ける - 証明と定義を分離 できて管理しやすい - 型レベルで安全性を担保 しやすくなる 15

    📌 Program機構のポイント - FixpointではなくProgram Fixpointなどとする - 関数定義の⼀部を _ で置き換える - Next Obligationで _ の部分の証明を書く 📌 Program機構の利点