我正在使用抽象语法树,在这里我想给绑定器自己的类型。这似乎给Idris的总体检查带来了问题...
通过典型的自我推荐Tree
,Idris可以很好地进行总计检查。
data TreeShape = Last | More TreeShape TreeShape
Show TreeShape where
show Last = "Leaf"
show (More left right) = "Branch " ++ show left ++ " " ++ show right
与Tree
相互一样:
mutual
data MuTree = Another MuMuTree
data MuMuTree = TheLeaf | TheBranch MuTree MuMuTree
Show MuTree where
show (Another x) = show x
Show MuMuTree where
show TheLeaf = "Leaf"
show (TheBranch left right) = "Branch " ++ show left ++ " " ++ show right
但是,通过对提取的类型进行参数化来引入间接性,并且总计检查将失败:
data LeftBranch t = L t
(Show t) => Show (LeftBranch t) where
show (L x) = show x
data TreeOutline = Final | Split (LeftBranch TreeOutline) TreeOutline
Show TreeOutline where
show Final = "Leaf"
show (Split left right) = "Branch " ++ show left ++ " " ++ show right
有没有办法让Idris正确检查最后一种递归类型的总数?简而言之,除了在代码中撒上assert_total
s之外还有什么吗?