简体   繁体   English

在Agda中键入Hierarchy

[英]Type Hierarchy in Agda

I am trying to figure out how type hierarchies work in Agda. 我试图找出类型层次结构如何在Agda中工作。

Assuming I define a set type X: 假设我定义了一个集合类型X:

X : Set 

and then proceed to constructing an inductive type 然后继续构建归纳型

data Y : X -> Set where

What is the type of X -> Set ? 什么是X -> Set Is it Set or Type? 是设置还是类型?

Thank you! 谢谢!

Well, why not ask Agda itself? 好吧,为什么不问阿格达呢? I'm going to use excellent Agda mode for Emacs. 我将为Emacs使用出色的Agda模式。 We start with: 我们从:

module Hierarchy where

postulate
  X : Set

data Y : X → Set where
  -- empty

We have to load the file using Cc Cl ; 我们必须使用Cc Cl加载文件; this typechecks the file, turns ? 这个typechecks文件,转? s into holes, does syntax highlighting and so on. 进入洞,语法高亮等等。

Now, there is a command "Infer (deduce) type" available via Cc Cd , so let's use that: 现在,有一个命令“推断(演绎)类型”可以通过Cc Cd ,所以让我们使用:

> C-c C-d
Expression:
> Y
X → Set

Right, that makes sense. 对,这是有道理的。 We defined Y : X → Set , so it should come as no surprise. 我们定义了Y : X → Set ,所以它应该不足为奇。 Let's ask again: 我们再问一遍:

> C-c C-d
Expression:
> X → Set
Set₁

So, there you have it: Y : X → Set : Set₁ . 所以,你有它: Y : X → Set : Set₁


While the first part answers the question and shows you how to check this stuff yourself, doing that everytime would be dull, at least. 虽然第一部分回答了问题,并向您展示了如何自己检查这些东西,但每次这样做都会变得乏味,至少。 Here's how it works: 以下是它的工作原理:

To avoid paradoxes, we require 为避免悖论,我们要求

Set i : Set (i + 1)

which gives you the (infinite) hierarchy of Set s. 它为您提供了Set的(无限)层次结构。 If you had Set : Set (which Agda allows via the --type-in-type flag), you could derive contradiction such as this one . 如果你已经Set : Set (这阿格达通过允许--type-in-type标志),可以推导出矛盾,比如这一个

This also gives us a simple rule for functions: 这也为我们提供了一个简单的函数规则:

A : Set i
B : A → Set j

(a : A) → B a : Set (max i j)

Applying this to your example: 将此应用于您的示例:

X   : Set
Set : Set₁

X → Set : Set (max 0 1)
X → Set : Set₁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM