使用更高级别的类型时,错误消息 "Universe inconsistency" 是什么意思?
What does the error message "Universe inconsistency" mean when working with higher-rank types?
给定以下 Idris 代码:
import Data.Vect
import Data.Fin
%default total
fins : Vect n (Fin n)
fins {n = Z} = []
fins {n = S n} = FZ :: map FS fins
Permutation : Nat -> Type
Permutation n = {a : Type} -> Vect n a -> Vect n a
permutations : {n : Nat} -> Vect (fact n) (Permutation n)
permutations {n = Z} = [id]
permutations {n = S n} =
rewrite multCommutative (S n) (fact n) in
concat $ map inserts (permutations {n = n})
where
inserts : Permutation k -> Vect (S k) (Permutation (S k))
inserts pi = map (\i => \(x :: xs) => insertAt i x . pi $ xs) fins
我从 Idris 0.9.16 收到以下错误消息(没有更多详细信息):
Type checking .\Permutations.idr
Permutations.idr:15:14:Universe inconsistency
然而,只要稍微改变一下,permutations
的第二个子句就变成了
permutations {n = S n} =
rewrite multCommutative (S n) (fact n) in
concat . map inserts $ permutations {n = n}
然后它突然进行类型检查。
在处理 ($)
和 (.)
、similar to what GHC does 时,Idris 内部是否有一些特殊的魔法,以便它们在更高级别的类型存在的情况下工作?
从 Idris 0.10.2 开始,我的原始代码(在 permutations
的定义中使用 concat $ map inserts (permutations {n = n})
)进行类型检查时没有打嗝。
给定以下 Idris 代码:
import Data.Vect
import Data.Fin
%default total
fins : Vect n (Fin n)
fins {n = Z} = []
fins {n = S n} = FZ :: map FS fins
Permutation : Nat -> Type
Permutation n = {a : Type} -> Vect n a -> Vect n a
permutations : {n : Nat} -> Vect (fact n) (Permutation n)
permutations {n = Z} = [id]
permutations {n = S n} =
rewrite multCommutative (S n) (fact n) in
concat $ map inserts (permutations {n = n})
where
inserts : Permutation k -> Vect (S k) (Permutation (S k))
inserts pi = map (\i => \(x :: xs) => insertAt i x . pi $ xs) fins
我从 Idris 0.9.16 收到以下错误消息(没有更多详细信息):
Type checking .\Permutations.idr
Permutations.idr:15:14:Universe inconsistency
然而,只要稍微改变一下,permutations
的第二个子句就变成了
permutations {n = S n} =
rewrite multCommutative (S n) (fact n) in
concat . map inserts $ permutations {n = n}
然后它突然进行类型检查。
在处理 ($)
和 (.)
、similar to what GHC does 时,Idris 内部是否有一些特殊的魔法,以便它们在更高级别的类型存在的情况下工作?
从 Idris 0.10.2 开始,我的原始代码(在 permutations
的定义中使用 concat $ map inserts (permutations {n = n})
)进行类型检查时没有打嗝。