PasteRack.org
Paste # 93026
2020-06-08 14:40:59

Forked from paste # 31619.

Fork as a new paste.

Paste viewed 744 times.


Embed:

typed-make-matrix

#lang typed/racket

(require racket/vector)

(define-type (Matrixof a) (Mutable-Vectorof (Mutable-Vectorof a)))

(: make-matrix (∀ (A) Integer Integer A -> (Matrixof A)))
(define (make-matrix i j fill)
  (let ((v : (Mutable-Vectorof (Mutable-Vectorof A)) (make-vector i (make-vector 0 fill)))
        (w (make-vector j fill)))
    (for ((idx (in-range 0 i)))
      (vector-set! v idx (vector-copy w)))
    v))