I'm new to Irdis. Is it possible to reverse a HVect
? If I call reverse on a HVect [String, Int]
it should return a HVect [Int, String]
and if I call reverse on a HVect [String, Int, Day]
it should return a HVect [Day, Int, String]
.
I tried to reuse Data.Vect.reverse
(Gist)
module reverse_hvect
import Data.HVect
reverse : HVect ts -> HVect (reverse ts)
reverse [] = []
reverse (x::xs) = (reverse xs) ++ [x]
but I get
Type checking .\reverse_hvect.idr
reverse_hvect.idr:7:9:When checking right hand side of reverse_hvect.reverse with expected type
HVect (reverse (t :: ts))
Type mismatch between
HVect (Data.Vect.reverse, go Type k ts [] ts ++ [t]) (Type of reverse xs ++ [x])
and
HVect (Data.Vect.reverse, go Type (S k) (t :: ts) [t] ts) (Expected type)
Specifically:
Type mismatch between
Data.Vect.reverse, go Type k ts [] ts ++ [t]
and
Data.Vect.reverse, go Type (S k) (t :: ts) [t] ts
Holes: reverse_hvect.reverse
Since Data.Vect.reverse
uses an inner function go
with an accumulator, I wrote my own Vect.reverse
with the same structure as my HVect.reverse
(Gist)
module reverse_hvect
import Data.Vect
import Data.HVect
myReverse : Vect n a -> Vect n a
myReverse [] = []
myReverse {n = S k} (x::xs) = rewrite plusCommutative 1 k in (myReverse xs) ++ [x]
reverse : HVect ts -> HVect (myReverse ts)
reverse [] = []
reverse (x::xs) = (reverse xs) ++ [x]
but I get another error
Type checking .\reverse_hvect.idr
reverse_hvect.idr:12:9:When checking right hand side of reverse_hvect.reverse with expected type
HVect (myReverse (t :: ts))
Type mismatch between
HVect (myReverse ts ++ [t]) (Type of reverse xs ++ [x])
and
HVect (replace (sym (replace (sym (replace (sym (plusZeroRightNeutral k)) Refl)) (replace (sym (plusSuccRightSucc k 0)) Refl))) (myReverse ts ++ [t])) (Expected type)
Specifically:
Type mismatch between
myReverse ts ++ [t]
and
replace (sym (replace (sym (replace (sym (plusZeroRightNeutral k)) Refl)) (replace (sym (plusSuccRightSucc k 0)) Refl))) (myReverse ts ++ [t])
Holes: reverse_hvect.reverse