2
我有一個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
當我檢查的wheels
從REPL總的煩躁,
:total wheels
Main.wheels is Total
,因爲我沒有在wheels
處理Tram
型,我不明白怎麼wheels
可總。我誤解了「總數」是什麼意思?
OMG這是一個可怕的功能。這是否也意味着'數據Vehicle:PowerSource - > Type Unicycle:Vehicle Pedal;摩托車:汽油車;電車:車輛電力',像'總車輪:車輛踏板 - >納特;輪子獨輪車= 1;輪子摩托車= 2'會以同樣的方式檢測嗎? – Cactus
在這個例子中,構造函數不接受參數,因此它們將類型檢查作爲應用程序檢查到構造函數,因此'wheels'不會是全部。正如我所說,這是呃意外的特徵,這是另一種說錯的方式。我們應該儘快解決它。 –