我的Vehicle
类型取决于PowerSource
类型:
data PowerSource = Petrol | Pedal | Electric
data Vehicle : PowerSource -> Type where
Unicycle : Vehicle Pedal
Motorcycle : (fuel: Nat) -> Vehicle Petrol
Tram: (battery : Nat) -> Vehicle Electric
和一个函数wheels
。 Tram
是一个未处理的案例。
wheels : Vehicle power -> Nat
wheels Unicycle = 1
wheels Motorcycle = 2
当我从REPL中检查wheels
的总数时,
:total wheels
Main.wheels is Total
由于我没有处理Tram
中的wheels
类型,因此我不明白wheels
的总体情况。我误解了“总数”是什么意思吗?
答案 0 :(得分:6)
这是因为在wheels Motorcycle
中它将Motorcycle
视为一个变量,因为它没有很好地作为构造函数应用程序输入 - Motorcycle
构造函数接受一个参数。
事实上,它超越了类型检查器是非常令人惊讶的,我认为这实际上是伊德里斯设计中的一个(可修复的)错误。为了避免这种错误,我认为它应该只允许模式变量自动绑定,如果它们以小写字母开头,就像绑定类型变量一样。