为什么zipWith (-) [6,5,4] [1,2,3]
在Idris失败?如果不编写专门的zipWith函数,是否可以避免该错误?
main8.idr:
module Main
import Data.HVect
import Data.Vect
import Data.Vect.Quantifiers
t : Vect 3 Nat
t = zipWith (-) [6,5,4] [1,2,3]
错误:
*main8> :load main8.idr
Type checking ./main8.idr
main8.idr:8:3:When checking right hand side of t with expected type
Vect 3 Nat
When checking argument f to function Data.Vect.zipWith:
Can't disambiguate since no name has a suitable type:
Prelude.Interfaces.-, Prelude.Nat.-
Holes: Main.t
此文件有效:
module Main
import Data.HVect
import Data.Vect
import Data.Vect.Quantifiers
vm : (ms : Vect l Nat) -> (ns : Vect l Nat) -> {auto p : All (uncurry LTE) (zip ns ms)} -> Vect l Nat
vm [] [] = []
vm {p = _ :: _} (m::ms) (n::ns) = m - n :: vm ms ns
t : Vect 3 Nat
t = vm [6,5,4] [1,2,3]