在Idris中,通常将List
定义如下:
data List a = Nil | (::) a (List a)
但是我想尝试使用递归List
函数来定义没有data
的{{1}}:
Type -> Type
这可以编译,但是在List' : Type -> Type
List' a = Either () (a, List' a)
情况下我无法匹配。例如,如果我定义
Either
编译器说:
isEmpty : List' a -> Bool
isEmpty (Left _) = True
isEmpty (Right _) = False
因此类型检查器似乎没有将When checking left hand side of isEmpty:
When checking an application of Main.isEmpty:
Type mismatch between
Either a1 b (Type of Left l)
and
List' a (Expected type)
扩展到其List' a
定义中。似乎类型定义中的递归调用会触发类型检查器-如果我改为像这样定义Either _ _
:
List'
然后将List' a = Either () (a, ())
定义编译正确。 (当然,它实际上不再是列表了。)
我想知道的是:
data
?