www

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

ack.mlish (719B)


      1 #lang s-exp "../../mlish.rkt"
      2 (require "../rackunit-typechecking.rkt")
      3 
      4 ;; tests cond with else
      5 
      6 (define (ack/else [m : Int] [n : Int] -> Int)
      7   (cond 
      8    [(zero? m) (add1 n)]
      9    [(zero? n) (ack/else (sub1 m) 1)]
     10    [else 
     11     (ack/else (sub1 m) (ack/else m (sub1 n)))]))
     12 
     13 (check-type (ack/else 0 0) : Int -> 1)
     14 (check-type (ack/else 1 1) : Int -> 3)
     15 (check-type (ack/else 2 2) : Int -> 7)
     16 (check-type (ack/else 3 4) : Int -> 125)
     17 
     18 (define (ack [m : Int] [n : Int] -> Int)
     19   (cond 
     20    [(zero? m) (add1 n)]
     21    [(zero? n) (ack (sub1 m) 1)]
     22    [#t (ack (sub1 m) (ack m (sub1 n)))]))
     23 
     24 (check-type (ack 0 0) : Int -> 1)
     25 (check-type (ack 1 1) : Int -> 3)
     26 (check-type (ack 2 2) : Int -> 7)
     27 (check-type (ack 3 4) : Int -> 125)