I am practicing Idris, and I want to obtain a list of slices from a vector.
First, I defined the following window function which returns m elements from the index i onwards (i.e. xs[i:i+m]):
import Data.Vect
window : (i : Nat) -> (m : Nat) -> Vect (i + (m + n)) t -> Vect m t
window i m xs = take m (drop i xs)
This compiles just fine:
> window 0 3 [1,2,3,4,5]
[1, 2, 3] : Vect 3 Integer
Now, for example, I want ys to hold 2 such slices of size 3, each slice beginning at i:
xs : Vect 5 Int
xs = [1,2,3,4,5]
ys : List (Vect 3 Int)
ys = [window i 3 xs | i <- [0,2]]
However, I am getting the following type mismatch:
|
| ys = [window i 3 xs | i <- [0,2]]
| ~~~~~~~~~~~~~
When checking right hand side of ys with expected type
List (Vect 3 Int)
When checking an application of function Main.window:
Type mismatch between
Vect 5 Int (Type of xs)
and
Vect (i + (3 + n)) Int (Expected type)
Specifically:
Type mismatch between
5
and
plus i (plus 3 n)
I would expect i to unify with values from [0,2], i.e.:
ys = [window 0 3 xs, window 2 3 xs]
Is my definition of window wrong?