伊德里斯是否存在宇宙不一致的非常重要的例子?

时间:2016-06-18 15:21:15

标签: types idris

我问question关于伊德里斯'类型检查宇宙的方式。现在我尝试一些会导致宇宙不一致的例子。这是我能想到的最简单的一个

foo : Type
foo = Type

bar : Main.foo
bar = Main.foo

输出错误是:

test.idr:2:5:Universe inconsistency.
        Working on: z
        Old domain: (4,4)
        New domain: (4,3)
        Involved constraints: 
                ConstraintFC {uconstraint = z <= w, ufc = test.idr:2:5}
                ConstraintFC {uconstraint = y < z, ufc = test.idr:2:5}
                ConstraintFC {uconstraint = z <= w, ufc = test.idr:2:5}

除了上面的例子,还有更多真正的例子导致宇宙不一致吗?为什么它们不一致?

5 个答案:

答案 0 :(得分:4)

来自测试套件的这个:

https://github.com/idris-lang/Idris-dev/blob/master/test/universes002/universes002.idr

我觉得很难不小心做这件事:)。

答案 1 :(得分:1)

我能想到的是吉拉德的悖论,这会引起宇宙的不一致。但是,我想不出任何利用宇宙不一致性的现实世界的例子。

答案 2 :(得分:0)

我在一个愚蠢的时刻想出的一个是

equalTypesCommute -> x=y -> (x=y)=(y=x)
equalTypesCommute Refl = Refl

这当然会爆炸:)

答案 3 :(得分:0)

我偶然发现了这一点。这是一个很自然的定义,所以真的很令人惊讶。

Subset : Type -> Type
Subset a = a -> Type

Family : Type -> Type
Family a = Subset (Subset a)

familyIntersection : Family a -> Subset a
familyIntersection {a} f x = (u : Subset a) -> f u -> u x

这给出了输出(idris --check):

test.idr:2:12-20:
  |
2 | Subset a = a -> Type
  |            ~~~~~~~~~
Universe inconsistency.
        Working on: ./test.idr.l1
        Old domain: (4,4)
        New domain: (4,3)
        Involved constraints: 
                ConstraintFC {uconstraint = ./test.idr.l1 < ./test.idr.m1, ufc = test.idr:2:12-20}
                ConstraintFC {uconstraint = ./test.idr.l1 < ./test.idr.m1, ufc = test.idr:2:12-20}
                ConstraintFC {uconstraint = ./test.idr.v2 <= ./test.idr.l1, ufc = test.idr:8:30-57}

对于任何不熟悉的人来说,这是从集合论(按照我的看法,以最自然的方式)翻译为Idris的基本定义:如果元素在所有子集中,则该元素位于子集的交集中。换句话说,如果对于基本类型的每个子集,如果该子集在族中,则该元素在子集中,则该元素在交点中。

答案 4 :(得分:0)

无意中发现了这个。如果您省略 {ty: Type} ->,它会抱怨 Universe 不一致。不过不确定这不是编译器错误。

codata Conat = Z | S Conat

codata Covect : (len : Conat) -> ty -> Type where
  (::) :  ty -> Covect len ty -> Covect (S len) ty
  Nil  :  {ty: Type} -> Covect Z ty
  -- Nil  :  Covect Z ty       -- for some reason this messes with the universe 

stripe : Covect len (Covect len t) -> Covect len (List ty)
stripe [] = []
相关问题