www

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

fibo.mlish (538B)


      1 #lang s-exp "../../mlish.rkt"
      2 (require "../rackunit-typechecking.rkt")
      3 
      4 (define (fib [n : Int] -> Int)
      5   (cond 
      6    [(< n 2) 1]
      7    [else 
      8     (+ (fib (- n 2)) (fib (sub1 n)))]))
      9 
     10 (define (main [args : (Vector String)] -> Int)
     11   (let ([n (if (= (vector-length args) 0)
     12                1
     13                (string->number (vector-ref args 0)))])
     14     (fib n)))
     15 
     16 (check-type (main (vector "0")) : Int -> 1)
     17 
     18 (check-type (main (vector "1")) : Int -> 1)
     19 
     20 (check-type (main (vector "2")) : Int -> 2)
     21 
     22 (check-type (main (vector "22")) : Int -> 28657)