7

Why does zipWith (-) [6,5,4] [1,2,3] fail in Idris? Is it possible to avoid that error without writing a specialized zipWith function?

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]

Error:

*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

This file works:

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]
michaelmesser
  • 3,601
  • 2
  • 19
  • 42
  • Do you also want to keep the guarantee that we are not going to do subtraction like `x - y`, where `x < y`? So, `zipWith minus [6,5,4] [1,2,3]` is not a solution to your problem? – Anton Trunov Oct 16 '17 at 12:58
  • @AntonTrunov I would like keep the LTE constraint. This is not the actual problem I am having. It is a simplified case. The real problem involves mapping an HVect. – michaelmesser Oct 16 '17 at 14:28
  • What happens if you are explicit about the `(-)` you want to use? The one in Prelude.Nat has the LTE constraint. The one in Prelude.Interfaces doesn't. – Boyd Stephen Smith Jr. Nov 14 '17 at 02:05
  • @BoydStephenSmithJr. I'm asking how to deal with the LTE constraint. I know that I can avoid it. – michaelmesser Nov 14 '17 at 12:58
  • Yes, and I'm asking what happens if you tell Idris you want the LTE constraint by fully qualifying the `-` or other being *explicit* about which one, instead of depending on type-directed name resolution. – Boyd Stephen Smith Jr. Nov 16 '17 at 17:50

0 Answers0