www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ary.mlish (875B)


      1 #lang s-exp "../../mlish.rkt"
      2 (require "../rackunit-typechecking.rkt")
      3 
      4 ;; test vectors and for loops
      5 (define (main [args : (Vector String)] -> (× Int Int))
      6   (let* ([n (if (zero? (vector-length args))
      7                 1
      8                 (string->number (vector-ref args 0)))]
      9          [x  (make-vector n 0)]
     10          [y  (make-vector n 0)]
     11          [last (sub1 n)])
     12     (begin
     13       (for ([i (in-range n)]) 
     14         (vector-set! x i (add1 i)))
     15       (for* ([k (in-range 1000)]
     16              [i (in-range last -1 -1)])
     17         (vector-set! y i (+ (vector-ref x i) (vector-ref y i))))
     18       (tup (vector-ref y 0) 
     19            (vector-ref y last)))))
     20 
     21 (check-type (main (vector "100")) 
     22   : (× Int Int) -> (tup 1000 100000))
     23 (check-type (main (vector "1000")) 
     24   : (× Int Int) -> (tup 1000 1000000))
     25 (check-type (main (vector "10000")) 
     26   : (× Int Int) -> (tup 1000 10000000))