Let's say I want to transpose a 2 x n "matrix" (list of lists) mat
. The idiomatic way of doing so in racket is
(apply map list mat)
To do the same thing in typed/racket, I have to help the type checker a little. The type of map
in that case is
(All (c a b ...)
(-> (-> a b ... b c) (Listof a) (Listof b) ... b (Listof c)))
Since I'm dealing with a 2 x n matrix, I must instantiate both a and b as Number
:
(apply (inst map (Listof Number) Number Number)
(inst list Number)
mat)
If mat
was a 3 x n matrix,
(apply (inst map (Listof Number) Number Number Number)
(inst list Number)
mat)
Would do the trick. Now, let's say that I'm dealing with an m x n matrix where m is some unknown positive integer. Is there a general way of instantiating map that would work for any value of m?