lisp-random / HindleyMilner / tests.lisp

;;;; Some tests for `infer.lisp'.

(defmacro try (x)
  `(format t "~A~% :: ~A~%~%" ',x (derive-type ',x)))

 (cdr '(1 2 3)))
;; :: (LIST NUM)

 (lambda (x y)
   (if (car x)
       (car y)
       (length y))))
;; :: (-> (LIST BOOL) (LIST NUM) NUM)

 (letrec ((fact (lambda (x)
                  (if (< x 2)
                      (* x (fact (- x 1)))))))
;; :: (-> NUM NUM)

 (let ((ident (lambda (x) x)))
   (ident ident)))
;; :: (-> T4 T4)

 (letrec ((length (lambda (l)
                    (if (null? l)
                        (+ 1 (length (cdr l)))))))
;; :: (-> (LIST T4) NUM)

 (letrec ((map (lambda (f l)
                 (if (null? l)
                     (cons (f (car l))
                           (map f (cdr l)))))))
;; :: (-> (-> T10 T6) (LIST T10) (LIST T6))

 (lambda (x)
   (+ 4 (call/cc (lambda (exit)
                   (if (null? x)
                       (exit 0)
                       (length x)))))))
;; :: (-> (LIST T12) NUM)

 (let ((f (lambda (x) (* x x))))
;; :: (-> NUM NUM)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.