www

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

lin+cons-tests.rkt (726B)


      1 #lang s-exp turnstile/examples/linear/lin+cons
      2 (require turnstile/rackunit-typechecking)
      3 
      4 
      5 (define (length [lst : (MList Int)]) Int
      6   (match-list lst
      7     [(cons _ xs @ l)
      8      (begin (drop l)
      9             (add1 (length xs)))]
     10     [(nil) 0]))
     11 
     12 (check-type (length (cons 9 (cons 8 (cons 7 (nil))))) : Int -> 3)
     13 
     14 
     15 
     16 (define (rev-append [lst : (MList String)]
     17                     [acc : (MList String)]) (MList String)
     18   (match-list lst
     19     [(cons x xs @ l) (rev-append xs (cons x acc @ l))]
     20     [(nil) acc]))
     21 
     22 (define (rev [lst : (MList String)]) (MList String)
     23   (rev-append lst (nil)))
     24 
     25 
     26 (check-type (rev (cons "a" (cons "b" (cons "c" (nil)))))
     27             : (MList String)
     28             -> (cons "c" (cons "b" (cons "a" (nil)))))