Remove trailing whitespace.
This commit is contained in:
parent
b5e4515752
commit
43efe6adf0
|
@ -2,7 +2,7 @@
|
||||||
(exn-pred exn:fail:contract?)
|
(exn-pred exn:fail:contract?)
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module m typed-scheme
|
(module m typed-scheme
|
||||||
(: f Any)
|
(: f Any)
|
||||||
(define f (lambda: ([x : Number]) (add1 x)))
|
(define f (lambda: ([x : Number]) (add1 x)))
|
||||||
(provide f))
|
(provide f))
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(module n2 scheme/base
|
(module n2 scheme/base
|
||||||
|
|
||||||
(require 'm scheme/match)
|
(require 'm scheme/match)
|
||||||
(match my-x
|
(match my-x
|
||||||
[(struct x (f)) (f #f)]))
|
[(struct x (f)) (f #f)]))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module square typed-scheme
|
(module square typed-scheme
|
||||||
|
|
||||||
;(provide: [square (Integer -> Integer)])
|
;(provide: [square (Integer -> Integer)])
|
||||||
(provide: [square (Integer -> Integer)])
|
(provide: [square (Integer -> Integer)])
|
||||||
;(: square (Number -> Number))
|
;(: square (Number -> Number))
|
||||||
|
@ -10,9 +10,9 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
(module squareclient typed-scheme
|
(module squareclient typed-scheme
|
||||||
|
|
||||||
(require 'square)
|
(require 'square)
|
||||||
|
|
||||||
(square 10) ;; 100
|
(square 10) ;; 100
|
||||||
(integer? 10.1) ;; #f
|
(integer? 10.1) ;; #f
|
||||||
(square 10.1) ;; 102.009999...
|
(square 10.1) ;; 102.009999...
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module before typed/scheme
|
(module before typed/scheme
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define-struct: Sigil ())
|
(define-struct: Sigil ())
|
||||||
|
|
||||||
(: list->english ((Listof String) -> String))
|
(: list->english ((Listof String) -> String))
|
||||||
(define (list->english strs) (error 'fail))
|
(define (list->english strs) (error 'fail))
|
||||||
|
|
||||||
(define-type-alias (Set X) (HashTable X '()))
|
(define-type-alias (Set X) (HashTable X '()))
|
||||||
|
|
||||||
(: empty-set (All (T) (-> (Set T))))
|
(: empty-set (All (T) (-> (Set T))))
|
||||||
(define (empty-set) (error 'fail))
|
(define (empty-set) (error 'fail))
|
||||||
|
|
||||||
(: set->list (All (T) ((Set T) -> (Listof T))))
|
(: set->list (All (T) ((Set T) -> (Listof T))))
|
||||||
(define (set->list set) (error 'fail))
|
(define (set->list set) (error 'fail))
|
||||||
)
|
)
|
||||||
|
|
||||||
(module after typed/scheme
|
(module after typed/scheme
|
||||||
(require 'before)
|
(require 'before)
|
||||||
|
|
||||||
(: f ((Set Sigil) -> Any))
|
(: f ((Set Sigil) -> Any))
|
||||||
(define (f x1)
|
(define (f x1)
|
||||||
(let* ([x2 (set->list x1)])
|
(let* ([x2 (set->list x1)])
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed/racket
|
#lang typed/racket
|
||||||
(car (car
|
(car (car
|
||||||
(parameterize ((current-input-port (open-input-string "2")))
|
(parameterize ((current-input-port (open-input-string "2")))
|
||||||
((inst port->list (List Number))))))
|
((inst port->list (List Number))))))
|
||||||
|
|
|
@ -3,19 +3,19 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module T typed-scheme
|
(module T typed-scheme
|
||||||
|
|
||||||
(define-struct: [a] thing ([get : a]))
|
(define-struct: [a] thing ([get : a]))
|
||||||
|
|
||||||
(: thing->string ((thing String) -> String))
|
(: thing->string ((thing String) -> String))
|
||||||
(define (thing->string x)
|
(define (thing->string x)
|
||||||
(string-append "foo" (thing-get x)))
|
(string-append "foo" (thing-get x)))
|
||||||
|
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(module U scheme
|
(module U scheme
|
||||||
|
|
||||||
(require 'T)
|
(require 'T)
|
||||||
|
|
||||||
(thing->string (make-thing 5)))
|
(thing->string (make-thing 5)))
|
||||||
|
|
||||||
(require 'U)
|
(require 'U)
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
#lang racket/load
|
#lang racket/load
|
||||||
|
|
||||||
(module T typed/racket
|
(module T typed/racket
|
||||||
|
|
||||||
(struct: [X] doll ([contents : X]))
|
(struct: [X] doll ([contents : X]))
|
||||||
|
|
||||||
(define-type RussianDoll
|
(define-type RussianDoll
|
||||||
(Rec RD (U 'center (doll RD))))
|
(Rec RD (U 'center (doll RD))))
|
||||||
|
|
||||||
(: f (RussianDoll -> RussianDoll))
|
(: f (RussianDoll -> RussianDoll))
|
||||||
(define (f rd) rd)
|
(define (f rd) rd)
|
||||||
|
|
||||||
(: md (All (x) (x -> (doll x))))
|
(: md (All (x) (x -> (doll x))))
|
||||||
(define md doll)
|
(define md doll)
|
||||||
|
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(module U racket
|
(module U racket
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
;; should FAIL!
|
;; should FAIL!
|
||||||
|
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(let*: ((x : Any 1)
|
(let*: ((x : Any 1)
|
||||||
(f : (-> Void) (lambda () (set! x (quote foo)))))
|
(f : (-> Void) (lambda () (set! x (quote foo)))))
|
||||||
(if (number? x) (begin (f) (add1 x)) 12))
|
(if (number? x) (begin (f) (add1 x)) 12))
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module A scheme
|
(module A scheme
|
||||||
|
|
||||||
(define (f x) (add1 x))
|
(define (f x) (add1 x))
|
||||||
|
|
||||||
(provide f))
|
(provide f))
|
||||||
|
|
||||||
(module B typed/scheme
|
(module B typed/scheme
|
||||||
|
|
||||||
(require/typed 'A [f (Integer -> Integer)])
|
(require/typed 'A [f (Integer -> Integer)])
|
||||||
|
|
||||||
(let ()
|
(let ()
|
||||||
|
|
||||||
(: x Integer)
|
(: x Integer)
|
||||||
(define x (f x))
|
(define x (f x))
|
||||||
|
|
||||||
(void)))
|
(void)))
|
||||||
|
|
||||||
(require 'B)
|
(require 'B)
|
||||||
|
|
|
@ -29,23 +29,23 @@
|
||||||
|
|
||||||
(define (cfile file)
|
(define (cfile file)
|
||||||
((compile-zos #f) (list file) 'auto))
|
((compile-zos #f) (list file) 'auto))
|
||||||
|
|
||||||
(define (exn-pred p)
|
(define (exn-pred p)
|
||||||
(let ([sexp (with-handlers
|
(let ([sexp (with-handlers
|
||||||
([exn:fail? (lambda _ #f)])
|
([exn:fail? (lambda _ #f)])
|
||||||
(call-with-input-file*
|
(call-with-input-file*
|
||||||
p
|
p
|
||||||
(lambda (prt)
|
(lambda (prt)
|
||||||
(read-line prt 'any) (read prt))))])
|
(read-line prt 'any) (read prt))))])
|
||||||
(match sexp
|
(match sexp
|
||||||
[(list-rest 'exn-pred e)
|
[(list-rest 'exn-pred e)
|
||||||
(eval `(exn-matches . ,e) (namespace-anchor->namespace a))]
|
(eval `(exn-matches . ,e) (namespace-anchor->namespace a))]
|
||||||
[_
|
[_
|
||||||
(exn-matches ".*Type Checker.*" exn:fail:syntax?)])))
|
(exn-matches ".*Type Checker.*" exn:fail:syntax?)])))
|
||||||
|
|
||||||
(define (mk-tests dir loader test)
|
(define (mk-tests dir loader test)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(define path (build-path (this-expression-source-directory) dir))
|
(define path (build-path (this-expression-source-directory) dir))
|
||||||
(define tests
|
(define tests
|
||||||
(for/list ([p (directory-list path)]
|
(for/list ([p (directory-list path)]
|
||||||
#:when (scheme-file? p)
|
#:when (scheme-file? p)
|
||||||
|
@ -64,10 +64,10 @@
|
||||||
(make-test-suite dir tests)))
|
(make-test-suite dir tests)))
|
||||||
|
|
||||||
(define (dr p)
|
(define (dr p)
|
||||||
(parameterize ([current-namespace (make-base-empty-namespace)])
|
(parameterize ([current-namespace (make-base-empty-namespace)])
|
||||||
(dynamic-require `(file ,(if (string? p) p (path->string p))) #f)))
|
(dynamic-require `(file ,(if (string? p) p (path->string p))) #f)))
|
||||||
|
|
||||||
(define succ-tests (mk-tests "succeed"
|
(define succ-tests (mk-tests "succeed"
|
||||||
dr
|
dr
|
||||||
(lambda (p thnk) (check-not-exn thnk))))
|
(lambda (p thnk) (check-not-exn thnk))))
|
||||||
(define fail-tests (mk-tests "fail"
|
(define fail-tests (mk-tests "fail"
|
||||||
|
|
|
@ -28,7 +28,7 @@ TR opt: real-part-loop.rkt 33:17 3.6 -- float-arg-expr in complex ops
|
||||||
|
|
||||||
(ann
|
(ann
|
||||||
(let loop ([v 0.0+1.0i])
|
(let loop ([v 0.0+1.0i])
|
||||||
(if (> (real-part v) 70000.2)
|
(if (> (real-part v) 70000.2)
|
||||||
0
|
0
|
||||||
(loop (+ v 3.6))))
|
(loop (+ v 3.6))))
|
||||||
Integer)
|
Integer)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
["--just" path "run only this test" (single (just-one path))]
|
["--just" path "run only this test" (single (just-one path))]
|
||||||
["--nightly" "for the nightly builds" (begin (nightly? #t) (unit? #t) (opt? #t))]
|
["--nightly" "for the nightly builds" (begin (nightly? #t) (unit? #t) (opt? #t))]
|
||||||
["--all" "run all tests" (begin (unit? #t) (int? #t) (opt? #t) (missed-opt? #t) (bench? #t))]
|
["--all" "run all tests" (begin (unit? #t) (int? #t) (opt? #t) (missed-opt? #t) (bench? #t))]
|
||||||
["--gui" "run using the gui"
|
["--gui" "run using the gui"
|
||||||
(if (gui-available?)
|
(if (gui-available?)
|
||||||
(begin (exec go))
|
(begin (exec go))
|
||||||
(error "GUI not available"))])
|
(error "GUI not available"))])
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
(define-type-alias top Any)
|
(define-type-alias top Any)
|
||||||
(define-type-alias set (top -> top))
|
(define-type-alias set (top -> top))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
;; CHANGES
|
;; CHANGES
|
||||||
;; added annotations on all bound variables and structs
|
;; added annotations on all bound variables and structs
|
||||||
;; require typed foldl
|
;; require typed foldl
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
;; added annotation on use of polymorphic functions in higher-order contexts
|
;; added annotation on use of polymorphic functions in higher-order contexts
|
||||||
|
|
||||||
;; fixme -- how do we require polymorphic functions?
|
;; fixme -- how do we require polymorphic functions?
|
||||||
#;(require (only (lib "list.ss") foldl))
|
#;(require (only (lib "list.ss") foldl))
|
||||||
#;(require (only "typed-list.ss" foldl))
|
#;(require (only "typed-list.ss" foldl))
|
||||||
|
|
||||||
(define-type-alias number Number)
|
(define-type-alias number Number)
|
||||||
|
@ -64,11 +64,11 @@
|
||||||
(car (queue-front q)))
|
(car (queue-front q)))
|
||||||
|
|
||||||
(pdefine: (a) (elements: [q : (queue a)]) : (Listof a)
|
(pdefine: (a) (elements: [q : (queue a)]) : (Listof a)
|
||||||
(append (queue-front q)
|
(append (queue-front q)
|
||||||
(reverse (queue-rear q))))
|
(reverse (queue-rear q))))
|
||||||
|
|
||||||
(pdefine: (a b) (fold [f : (a b -> b)] [init : b] [q : (queue a)]) : b
|
(pdefine: (a b) (fold [f : (a b -> b)] [init : b] [q : (queue a)]) : b
|
||||||
(foldl f
|
(foldl f
|
||||||
(foldl f init (queue-front q))
|
(foldl f init (queue-front q))
|
||||||
(reverse (queue-rear q))))
|
(reverse (queue-rear q))))
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
(+ (length (queue-front q))
|
(+ (length (queue-front q))
|
||||||
(length (queue-rear q))))
|
(length (queue-rear q))))
|
||||||
|
|
||||||
;; 12 definitions checked
|
;; 12 definitions checked
|
||||||
;; generators removed
|
;; generators removed
|
||||||
|
|
||||||
;; TESTS
|
;; TESTS
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(let: ([x : Number 1])
|
(let: ([x : Number 1])
|
||||||
(let-syntax ([m (syntax-rules ()
|
(let-syntax ([m (syntax-rules ()
|
||||||
[(_) x])])
|
[(_) x])])
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
(define-type-alias top Any)
|
(define-type-alias top Any)
|
||||||
|
|
||||||
(define: a : (number -> number) (lambda: ([x : number]) x))
|
(define: a : (number -> number) (lambda: ([x : number]) x))
|
||||||
(define: f : (case-lambda (number -> number)
|
(define: f : (case-lambda (number -> number)
|
||||||
(boolean boolean -> boolean))
|
(boolean boolean -> boolean))
|
||||||
(case-lambda
|
(case-lambda
|
||||||
[(#{x : number}) (add1 x)]
|
[(#{x : number}) (add1 x)]
|
||||||
[(#{a : boolean} #{b : boolean}) (and a b)]))
|
[(#{a : boolean} #{b : boolean}) (and a b)]))
|
||||||
|
|
||||||
(define: f* : (case-lambda (number -> number)
|
(define: f* : (case-lambda (number -> number)
|
||||||
(boolean boolean -> boolean))
|
(boolean boolean -> boolean))
|
||||||
(case-lambda:
|
(case-lambda:
|
||||||
[([x : number]) (add1 x)]
|
[([x : number]) (add1 x)]
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
|
|
||||||
(: append-one (case-lambda (EvenParity -> OddParity)
|
(: append-one (case-lambda (EvenParity -> OddParity)
|
||||||
(OddParity -> EvenParity)
|
(OddParity -> EvenParity)
|
||||||
(Bitstring -> Bitstring)))
|
(Bitstring -> Bitstring)))
|
||||||
(define (append-one l)
|
(define (append-one l)
|
||||||
(if (null? l)
|
(if (null? l)
|
||||||
(make-O '())
|
(make-O '())
|
||||||
(if (Z? l)
|
(if (Z? l)
|
||||||
(make-Z (append-one (Z-b l)))
|
(make-Z (append-one (Z-b l)))
|
||||||
(make-O (append-one (O-b l))))))
|
(make-O (append-one (O-b l))))))
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
(parameterize ((abort k))
|
(parameterize ((abort k))
|
||||||
body ...))))))
|
body ...))))))
|
||||||
|
|
||||||
(call-with-exception-handler
|
(call-with-exception-handler
|
||||||
(lambda (v) (displayln v) ((abort) v))
|
(lambda (v) (displayln v) ((abort) v))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-abort 2)
|
(with-abort 2)
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
(with-abort (raise-syntax-error #f "stx-err" 45))
|
(with-abort (raise-syntax-error #f "stx-err" 45))
|
||||||
(with-abort (raise-syntax-error #f "stx-err" 4 5))
|
(with-abort (raise-syntax-error #f "stx-err" 4 5))
|
||||||
(with-abort (raise-syntax-error #f "stx-err" 4 5 (list #'stx)))
|
(with-abort (raise-syntax-error #f "stx-err" 4 5 (list #'stx)))
|
||||||
|
|
||||||
(void)
|
(void)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
(define (check f a b)
|
(define (check f a b)
|
||||||
(if (f a b)
|
(if (f a b)
|
||||||
#t
|
#t
|
||||||
(error (format "Check (~a ~a ~a) failed" f a b))))
|
(error (format "Check (~a ~a ~a) failed" f a b))))
|
||||||
|
|
||||||
(check = (fx+ 1 2) 3)
|
(check = (fx+ 1 2) 3)
|
||||||
(check = (fx- 2 3) -1)
|
(check = (fx- 2 3) -1)
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
|
|
||||||
(: tfo-align Any)
|
(: tfo-align Any)
|
||||||
(define (tfo-align) 0.0
|
(define (tfo-align) 0.0
|
||||||
|
|
||||||
(let* ((x (FLOAT* 0.0 (FLOATsin 0.))))
|
(let* ((x (FLOAT* 0.0 (FLOATsin 0.))))
|
||||||
0))
|
0))
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
(define (check f a b)
|
(define (check f a b)
|
||||||
(if (f a b)
|
(if (f a b)
|
||||||
#t
|
#t
|
||||||
(error (format "Check (~a ~a ~a) failed" f a b))))
|
(error (format "Check (~a ~a ~a) failed" f a b))))
|
||||||
|
|
||||||
(: check-pred (All (a) ((a -> Boolean) a -> Boolean)))
|
(: check-pred (All (a) ((a -> Boolean) a -> Boolean)))
|
||||||
(define (check-pred pred v)
|
(define (check-pred pred v)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
(define (check f a b)
|
(define (check f a b)
|
||||||
(if (f a b)
|
(if (f a b)
|
||||||
#t
|
#t
|
||||||
(error (format "Check (~a ~a ~a) failed" f a b))))
|
(error (format "Check (~a ~a ~a) failed" f a b))))
|
||||||
|
|
||||||
;; Check the FlVector type is exported
|
;; Check the FlVector type is exported
|
||||||
(define: v : FlVector (flvector 1. 2. 3.))
|
(define: v : FlVector (flvector 1. 2. 3.))
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
(if (or (null? as)
|
(if (or (null? as)
|
||||||
(ormap null? bss))
|
(ormap null? bss))
|
||||||
c
|
c
|
||||||
(apply (inst fold-left c a b ... b) f
|
(apply (inst fold-left c a b ... b) f
|
||||||
(apply f c (car as) (map car bss))
|
(apply f c (car as) (map car bss))
|
||||||
(cdr as) (map cdr bss))))
|
(cdr as) (map cdr bss))))
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
(if (or (null? as)
|
(if (or (null? as)
|
||||||
(ormap null? bss))
|
(ormap null? bss))
|
||||||
c
|
c
|
||||||
(apply fold-left f
|
(apply fold-left f
|
||||||
(apply f c (car as) (map car bss))
|
(apply f c (car as) (map car bss))
|
||||||
(cdr as) (map cdr bss))))
|
(cdr as) (map cdr bss))))
|
||||||
|
|
||||||
|
@ -19,21 +19,21 @@
|
||||||
(car as) (map car bss))))
|
(car as) (map car bss))))
|
||||||
|
|
||||||
;; Matthias -- tell me why this returns 4.
|
;; Matthias -- tell me why this returns 4.
|
||||||
((plambda: (x ...) [xs : x ... x]
|
((plambda: (x ...) [xs : x ... x]
|
||||||
(apply fold-left
|
(apply fold-left
|
||||||
(lambda: ([a : Integer] [b : Integer] . [xs : x ... x])
|
(lambda: ([a : Integer] [b : Integer] . [xs : x ... x])
|
||||||
(+ a b))
|
(+ a b))
|
||||||
3
|
3
|
||||||
(list 1 2 3)
|
(list 1 2 3)
|
||||||
(map list xs)))
|
(map list xs)))
|
||||||
3 4 5)
|
3 4 5)
|
||||||
|
|
||||||
((plambda: (x ...) [xs : x ... x]
|
((plambda: (x ...) [xs : x ... x]
|
||||||
(apply fold-right
|
(apply fold-right
|
||||||
(lambda: ([a : Integer] [b : Integer] . [xs : x ... x])
|
(lambda: ([a : Integer] [b : Integer] . [xs : x ... x])
|
||||||
(+ a b))
|
(+ a b))
|
||||||
3
|
3
|
||||||
(list 1 2 3)
|
(list 1 2 3)
|
||||||
(map list xs)))
|
(map list xs)))
|
||||||
3 4 5)
|
3 4 5)
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
(module foldo mzscheme
|
(module foldo mzscheme
|
||||||
(require (lib "file.ss")(lib "match.ss"))
|
(require (lib "file.ss")(lib "match.ss"))
|
||||||
(provide apply-to-scheme-files)
|
(provide apply-to-scheme-files)
|
||||||
|
|
||||||
(define-syntax (define-excluder stx)
|
(define-syntax (define-excluder stx)
|
||||||
|
|
||||||
(define (path->clause c)
|
(define (path->clause c)
|
||||||
(syntax-case c ()
|
(syntax-case c ()
|
||||||
[(item ...)
|
[(item ...)
|
||||||
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
||||||
[item
|
[item
|
||||||
#`[`(item) #t]]))
|
#`[`(item) #t]]))
|
||||||
|
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ name path ...)
|
[(_ name path ...)
|
||||||
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
||||||
#`(define (name p )
|
#`(define (name p )
|
||||||
(let* ([dirnames (map path->string (explode-path p))])
|
(let* ([dirnames (map path->string (explode-path p))])
|
||||||
(match (reverse dirnames) ; goofy backwards matching because ... matches greedily
|
(match (reverse dirnames) ; goofy backwards matching because ... matches greedily
|
||||||
match-clause ...
|
match-clause ...
|
||||||
[_ #f]))))]))
|
[_ #f]))))]))
|
||||||
|
|
||||||
(define-excluder default-excluder
|
(define-excluder default-excluder
|
||||||
"compiled" ".git")
|
"compiled" ".git")
|
||||||
|
|
||||||
(define exclude-directory? (make-parameter default-excluder))
|
(define exclude-directory? (make-parameter default-excluder))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; apply-to-scheme-files: (path[file] -> X) path[directory] -> (listof X)
|
;; apply-to-scheme-files: (path[file] -> X) path[directory] -> (listof X)
|
||||||
;; applies the given function to each .ss or .scm file in the given directory
|
;; applies the given function to each .ss or .scm file in the given directory
|
||||||
;; hierarchy; returns all results in a list
|
;; hierarchy; returns all results in a list
|
||||||
(define (apply-to-scheme-files f root )
|
(define (apply-to-scheme-files f root )
|
||||||
;;FOLD-FILES
|
;;FOLD-FILES
|
||||||
|
|
||||||
(fold-files
|
(fold-files
|
||||||
(lambda (path kind acc)
|
(lambda (path kind acc)
|
||||||
(case kind
|
(case kind
|
||||||
|
@ -42,17 +42,17 @@
|
||||||
[(regexp-match #rx"(rkt|rktl|ss|scm)$" extension)
|
[(regexp-match #rx"(rkt|rktl|ss|scm)$" extension)
|
||||||
(let ([resl (f path)])
|
(let ([resl (f path)])
|
||||||
(if resl
|
(if resl
|
||||||
(cons resl acc)
|
(cons resl acc)
|
||||||
acc ))]
|
acc ))]
|
||||||
[else acc ]))]
|
[else acc ]))]
|
||||||
[(dir)
|
[(dir)
|
||||||
(let* ([p (normalize-path path root)])
|
(let* ([p (normalize-path path root)])
|
||||||
(if ((exclude-directory?) p)
|
(if ((exclude-directory?) p)
|
||||||
(values acc #f)
|
(values acc #f)
|
||||||
acc ))]
|
acc ))]
|
||||||
[(link) acc ]
|
[(link) acc ]
|
||||||
[else (error "never happen")]))
|
[else (error "never happen")]))
|
||||||
'()
|
'()
|
||||||
root
|
root
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(provide x)
|
(provide x)
|
||||||
(set! x 4)
|
(set! x 4)
|
||||||
(when #t 3))
|
(when #t 3))
|
||||||
|
|
||||||
|
|
||||||
(module trequire typed-scheme
|
(module trequire typed-scheme
|
||||||
(require 'bang-tests)
|
(require 'bang-tests)
|
||||||
|
@ -18,31 +18,31 @@
|
||||||
|
|
||||||
(module require-tests typed-scheme
|
(module require-tests typed-scheme
|
||||||
(provide z)
|
(provide z)
|
||||||
(require/typed x Number 'm)
|
(require/typed x Number 'm)
|
||||||
(+ x 3)
|
(+ x 3)
|
||||||
(require/typed y (Number -> Number) 'm)
|
(require/typed y (Number -> Number) 'm)
|
||||||
(define: z : Number (y (+ x 4))))
|
(define: z : Number (y (+ x 4))))
|
||||||
|
|
||||||
|
|
||||||
(module provide-type typed-scheme
|
(module provide-type typed-scheme
|
||||||
(define-type-alias top2 Any)
|
(define-type-alias top2 Any)
|
||||||
|
|
||||||
(define-typed-struct (a) container ([v : a]))
|
(define-typed-struct (a) container ([v : a]))
|
||||||
|
|
||||||
(container-v (make-container 3))
|
(container-v (make-container 3))
|
||||||
|
|
||||||
(provide top2 container container-v make-container)
|
(provide top2 container container-v make-container)
|
||||||
)
|
)
|
||||||
|
|
||||||
(module require-type typed-scheme
|
(module require-type typed-scheme
|
||||||
(require 'provide-type)
|
(require 'provide-type)
|
||||||
|
|
||||||
(let: ([x : top2 3])
|
(let: ([x : top2 3])
|
||||||
x)
|
x)
|
||||||
|
|
||||||
(define: (f [x : (container Number)]) : Number
|
(define: (f [x : (container Number)]) : Number
|
||||||
(container-v x))
|
(container-v x))
|
||||||
|
|
||||||
(f (make-container (ann 7 : Number)))
|
(f (make-container (ann 7 : Number)))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
(define (list-length loa)
|
(define (list-length loa)
|
||||||
(list-length-helper loa 0))
|
(list-length-helper loa 0))
|
||||||
|#
|
|#
|
||||||
|
|
||||||
;; tests:
|
;; tests:
|
||||||
(= 0 (list-length '()))
|
(= 0 (list-length '()))
|
||||||
(= 2 (list-length '(1 2)))
|
(= 2 (list-length '(1 2)))
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
(define: y : Any "foo")
|
(define: y : Any "foo")
|
||||||
(if (and (number? x) (string? y))
|
(if (and (number? x) (string? y))
|
||||||
(+ x (string-length y))
|
(+ x (string-length y))
|
||||||
0)
|
0)
|
||||||
|
|
||||||
;; Example 6 has an intentional error
|
;; Example 6 has an intentional error
|
||||||
(define: z : (U Number String) 7)
|
(define: z : (U Number String) 7)
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
(require typed-scheme/base-env/extra-procs)
|
(require typed-scheme/base-env/extra-procs)
|
||||||
|
|
||||||
((inst map Number Number Number Number Number Number Number)
|
((inst map Number Number Number Number Number Number Number)
|
||||||
+
|
+
|
||||||
(list 1 2 3) (list 2 3 4) (list 1 2 3) (list 2 3 4) (list 1 2 3) (list 2 3 4))
|
(list 1 2 3) (list 2 3 4) (list 1 2 3) (list 2 3 4) (list 1 2 3) (list 2 3 4))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(open-input-file "foo" #:mode 'binary)
|
(open-input-file "foo" #:mode 'binary)
|
||||||
(open-input-file "foo" #:mode 'text)
|
(open-input-file "foo" #:mode 'text)
|
||||||
(open-input-file "foo"))
|
(open-input-file "foo"))
|
||||||
|
|
||||||
|
|
|
@ -33,27 +33,27 @@
|
||||||
(define-type-alias symbol Symbol)
|
(define-type-alias symbol Symbol)
|
||||||
(define-type-alias top Any)
|
(define-type-alias top Any)
|
||||||
(define-type-alias list-of Listof)
|
(define-type-alias list-of Listof)
|
||||||
(require
|
(require
|
||||||
(except-in srfi/67 current-compare =? <?)
|
(except-in srfi/67 current-compare =? <?)
|
||||||
#;"typed-list.ss"
|
#;"typed-list.ss"
|
||||||
#;srfi/42
|
#;srfi/42
|
||||||
#;(only mzlib/list foldl))
|
#;(only mzlib/list foldl))
|
||||||
|
|
||||||
#;(provide (all-defined))
|
#;(provide (all-defined))
|
||||||
(provide comparator Heap elements empty fold heap-node? find-min empty? insert insert* delete-min size union)
|
(provide comparator Heap elements empty fold heap-node? find-min empty? insert insert* delete-min size union)
|
||||||
|
|
||||||
#;(define-type-alias top top)
|
#;(define-type-alias top top)
|
||||||
|
|
||||||
(define-type-alias comparator (top top -> number))
|
(define-type-alias comparator (top top -> number))
|
||||||
|
|
||||||
;; fixme - type aliases should work in require
|
;; fixme - type aliases should work in require
|
||||||
|
|
||||||
(require/typed current-compare (-> (top top -> number)) srfi/67)
|
(require/typed current-compare (-> (top top -> number)) srfi/67)
|
||||||
(require/typed =? ((top top -> number) top top -> boolean) srfi/67)
|
(require/typed =? ((top top -> number) top top -> boolean) srfi/67)
|
||||||
(require/typed <? ((top top -> number) top top -> boolean) srfi/67)
|
(require/typed <? ((top top -> number) top top -> boolean) srfi/67)
|
||||||
|
|
||||||
;;; DATA DEFINITION
|
;;; DATA DEFINITION
|
||||||
|
|
||||||
; A HEAP is either
|
; A HEAP is either
|
||||||
; (make-heap-empty cmp)
|
; (make-heap-empty cmp)
|
||||||
; or
|
; or
|
||||||
|
@ -62,38 +62,38 @@
|
||||||
; cmp is a compare function,
|
; cmp is a compare function,
|
||||||
; rank is an integer, and
|
; rank is an integer, and
|
||||||
; left and right are heaps.
|
; left and right are heaps.
|
||||||
|
|
||||||
(define-typed-struct heap ([compare : comparator]))
|
(define-typed-struct heap ([compare : comparator]))
|
||||||
(define-typed-struct (heap-empty heap) ())
|
(define-typed-struct (heap-empty heap) ())
|
||||||
(define-typed-struct (a) (heap-node heap)
|
(define-typed-struct (a) (heap-node heap)
|
||||||
([rank : Real] [elm : a] [left : (Un (heap-node a) heap-empty)] [right : (Un (heap-node a) heap-empty)]))
|
([rank : Real] [elm : a] [left : (Un (heap-node a) heap-empty)] [right : (Un (heap-node a) heap-empty)]))
|
||||||
|
|
||||||
(define-type-alias (Heap a) (Un (heap-node a) heap-empty))
|
(define-type-alias (Heap a) (Un (heap-node a) heap-empty))
|
||||||
|
|
||||||
;;; CORE HEAP OPERATIONS
|
;;; CORE HEAP OPERATIONS
|
||||||
|
|
||||||
;; FIXME
|
;; FIXME
|
||||||
(: empty (All (a) (case-lambda (-> (Heap a)) (comparator -> (Heap a)))))
|
(: empty (All (a) (case-lambda (-> (Heap a)) (comparator -> (Heap a)))))
|
||||||
(define empty
|
(define empty
|
||||||
(case-lambda
|
(case-lambda
|
||||||
[() (make-heap-empty (current-compare))]
|
[() (make-heap-empty (current-compare))]
|
||||||
[(#{cmp : comparator}) (make-heap-empty cmp)]))
|
[(#{cmp : comparator}) (make-heap-empty cmp)]))
|
||||||
|
|
||||||
(define: empty? : (pred heap-empty) heap-empty?)
|
(define: empty? : (pred heap-empty) heap-empty?)
|
||||||
|
|
||||||
(pdefine: (a) (rank [h : (Heap a)]) : Real
|
(pdefine: (a) (rank [h : (Heap a)]) : Real
|
||||||
(if (empty? h)
|
(if (empty? h)
|
||||||
0
|
0
|
||||||
(heap-node-rank h)))
|
(heap-node-rank h)))
|
||||||
|
|
||||||
(pdefine: (a) (make [x : a] [a : (Heap a)] [b : (Heap a)]) : (Heap a)
|
(pdefine: (a) (make [x : a] [a : (Heap a)] [b : (Heap a)]) : (Heap a)
|
||||||
(let ([ra (rank a)]
|
(let ([ra (rank a)]
|
||||||
[rb (rank b)]
|
[rb (rank b)]
|
||||||
[cmp (heap-compare a)])
|
[cmp (heap-compare a)])
|
||||||
(if (>= ra rb)
|
(if (>= ra rb)
|
||||||
(make-heap-node cmp (add1 rb) x a b)
|
(make-heap-node cmp (add1 rb) x a b)
|
||||||
(make-heap-node cmp (add1 ra) x b a))))
|
(make-heap-node cmp (add1 ra) x b a))))
|
||||||
|
|
||||||
(pdefine: (a) (union [h1 : (Heap a)] [h2 : (Heap a)]) : (Heap a)
|
(pdefine: (a) (union [h1 : (Heap a)] [h2 : (Heap a)]) : (Heap a)
|
||||||
(cond
|
(cond
|
||||||
[(empty? h1) h2]
|
[(empty? h1) h2]
|
||||||
|
@ -103,23 +103,23 @@
|
||||||
(if<=? ((heap-compare h1) x y)
|
(if<=? ((heap-compare h1) x y)
|
||||||
(make x (heap-node-left h1) (union (heap-node-right h1) h2))
|
(make x (heap-node-left h1) (union (heap-node-right h1) h2))
|
||||||
(make y (heap-node-left h2) (union h1 (heap-node-right h2)))))]))
|
(make y (heap-node-left h2) (union h1 (heap-node-right h2)))))]))
|
||||||
|
|
||||||
(pdefine: (a) (insert [x : a] [h : (Heap a)]) : (Heap a)
|
(pdefine: (a) (insert [x : a] [h : (Heap a)]) : (Heap a)
|
||||||
(let: ([cmp : comparator (heap-compare h)])
|
(let: ([cmp : comparator (heap-compare h)])
|
||||||
(union (make-heap-node cmp 1 x (make-heap-empty cmp) (make-heap-empty cmp))
|
(union (make-heap-node cmp 1 x (make-heap-empty cmp) (make-heap-empty cmp))
|
||||||
h)))
|
h)))
|
||||||
|
|
||||||
;; No changes other than variable annotations
|
;; No changes other than variable annotations
|
||||||
(pdefine: (a) (delete [x : a] [h : (Heap a)]) : (Heap a)
|
(pdefine: (a) (delete [x : a] [h : (Heap a)]) : (Heap a)
|
||||||
(define: (delete/sf [x : a] [h : (Heap a)] [s : ((Heap a) -> (Heap a))] [f : (-> (Heap a))]) : (Heap a)
|
(define: (delete/sf [x : a] [h : (Heap a)] [s : ((Heap a) -> (Heap a))] [f : (-> (Heap a))]) : (Heap a)
|
||||||
(cond
|
(cond
|
||||||
[(empty? h)
|
[(empty? h)
|
||||||
(s h)]
|
(s h)]
|
||||||
[(=? (heap-compare h) x (heap-node-elm h))
|
[(=? (heap-compare h) x (heap-node-elm h))
|
||||||
(s (union (heap-node-left h) (heap-node-right h)))]
|
(s (union (heap-node-left h) (heap-node-right h)))]
|
||||||
[(<? (heap-compare h) x (heap-node-elm h))
|
[(<? (heap-compare h) x (heap-node-elm h))
|
||||||
(f)]
|
(f)]
|
||||||
[else
|
[else
|
||||||
(let ([cmp (heap-compare h)])
|
(let ([cmp (heap-compare h)])
|
||||||
(let ([y (heap-node-elm h)]
|
(let ([y (heap-node-elm h)]
|
||||||
[l (heap-node-left h)]
|
[l (heap-node-left h)]
|
||||||
|
@ -129,22 +129,22 @@
|
||||||
(lambda () (delete/sf x r
|
(lambda () (delete/sf x r
|
||||||
(lambda: ([h1 : (Heap a)]) (s (make y l h1)))
|
(lambda: ([h1 : (Heap a)]) (s (make y l h1)))
|
||||||
(lambda () (f)))))))]))
|
(lambda () (f)))))))]))
|
||||||
(delete/sf x h
|
(delete/sf x h
|
||||||
(lambda: ([h1 : (Heap a)]) h1)
|
(lambda: ([h1 : (Heap a)]) h1)
|
||||||
(lambda () h)))
|
(lambda () h)))
|
||||||
|
|
||||||
;; annotated w/ no errors
|
;; annotated w/ no errors
|
||||||
(pdefine: (a) (delete-all [x : a] [h : (Heap a)]) : (Heap a)
|
(pdefine: (a) (delete-all [x : a] [h : (Heap a)]) : (Heap a)
|
||||||
(define: (delete-all/sf [x : a] [h : (Heap a)] [s : ((Heap a) -> (Heap a))] [f : (-> (Heap a))]) : (Heap a)
|
(define: (delete-all/sf [x : a] [h : (Heap a)] [s : ((Heap a) -> (Heap a))] [f : (-> (Heap a))]) : (Heap a)
|
||||||
(cond
|
(cond
|
||||||
[(empty? h)
|
[(empty? h)
|
||||||
(s h)]
|
(s h)]
|
||||||
[(=? (heap-compare h) x (heap-node-elm h))
|
[(=? (heap-compare h) x (heap-node-elm h))
|
||||||
(s (union (delete-all x (heap-node-left h))
|
(s (union (delete-all x (heap-node-left h))
|
||||||
(delete-all x (heap-node-right h))))]
|
(delete-all x (heap-node-right h))))]
|
||||||
[(<? (heap-compare h) x (heap-node-elm h))
|
[(<? (heap-compare h) x (heap-node-elm h))
|
||||||
(f)]
|
(f)]
|
||||||
[else
|
[else
|
||||||
(let ([cmp (heap-compare h)])
|
(let ([cmp (heap-compare h)])
|
||||||
(let ([y (heap-node-elm h)]
|
(let ([y (heap-node-elm h)]
|
||||||
[l (heap-node-left h)]
|
[l (heap-node-left h)]
|
||||||
|
@ -156,13 +156,13 @@
|
||||||
(lambda () (delete-all/sf x r
|
(lambda () (delete-all/sf x r
|
||||||
(lambda: ([r1 : (Heap a)]) (s (make y l r1)))
|
(lambda: ([r1 : (Heap a)]) (s (make y l r1)))
|
||||||
(lambda () (f)))))))]))
|
(lambda () (f)))))))]))
|
||||||
(delete-all/sf x h
|
(delete-all/sf x h
|
||||||
(lambda: ([h1 : (Heap a)]) h1)
|
(lambda: ([h1 : (Heap a)]) h1)
|
||||||
(lambda () h)))
|
(lambda () h)))
|
||||||
|
|
||||||
(pdefine: (a) (find-min [h : (heap-node a)]) : a
|
(pdefine: (a) (find-min [h : (heap-node a)]) : a
|
||||||
(heap-node-elm h))
|
(heap-node-elm h))
|
||||||
|
|
||||||
(pdefine: (a) (delete-min [h : (heap-node a)]) : (Heap a)
|
(pdefine: (a) (delete-min [h : (heap-node a)]) : (Heap a)
|
||||||
(union (heap-node-left h) (heap-node-right h)))
|
(union (heap-node-left h) (heap-node-right h)))
|
||||||
|
|
||||||
|
@ -174,29 +174,29 @@
|
||||||
(if=? (cmp x (heap-node-elm h))
|
(if=? (cmp x (heap-node-elm h))
|
||||||
(s (heap-node-elm h))
|
(s (heap-node-elm h))
|
||||||
(inner-get (heap-node-left h) s
|
(inner-get (heap-node-left h) s
|
||||||
(lambda () (inner-get (heap-node-right h) s
|
(lambda () (inner-get (heap-node-right h) s
|
||||||
f))))))
|
f))))))
|
||||||
(inner-get h (lambda: ([x : a]) x) (lambda () #f))))
|
(inner-get h (lambda: ([x : a]) x) (lambda () #f))))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; EXTRA OPERATIONS
|
;;; EXTRA OPERATIONS
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(pdefine: (a) (delete* [xs : (list-of a)] [h : (Heap a)]) : (Heap a)
|
(pdefine: (a) (delete* [xs : (list-of a)] [h : (Heap a)]) : (Heap a)
|
||||||
(foldl {ann delete : (a (Heap a) -> (Heap a))} h xs))
|
(foldl {ann delete : (a (Heap a) -> (Heap a))} h xs))
|
||||||
|
|
||||||
(pdefine: (a r) (fold [f : (a r -> r)] [b : r] [h : (Heap a)]) : r
|
(pdefine: (a r) (fold [f : (a r -> r)] [b : r] [h : (Heap a)]) : r
|
||||||
(if (empty? h)
|
(if (empty? h)
|
||||||
b
|
b
|
||||||
(fold f
|
(fold f
|
||||||
(fold f
|
(fold f
|
||||||
(f (heap-node-elm h) b)
|
(f (heap-node-elm h) b)
|
||||||
(heap-node-left h))
|
(heap-node-left h))
|
||||||
(heap-node-right h))))
|
(heap-node-right h))))
|
||||||
|
|
||||||
(pdefine: (a) (elements [h : (Heap a)]) : (list-of a)
|
(pdefine: (a) (elements [h : (Heap a)]) : (list-of a)
|
||||||
(fold (lambda: ([x : a] [l : (list-of a)]) (cons x l)) '() h))
|
(fold (lambda: ([x : a] [l : (list-of a)]) (cons x l)) '() h))
|
||||||
|
|
||||||
(pdefine: (a) (count [x : a] [h : (Heap a)]) : number
|
(pdefine: (a) (count [x : a] [h : (Heap a)]) : number
|
||||||
(let ([cmp (heap-compare h)])
|
(let ([cmp (heap-compare h)])
|
||||||
(fold (lambda: ([y : a] [s : number])
|
(fold (lambda: ([y : a] [s : number])
|
||||||
|
@ -204,11 +204,11 @@
|
||||||
(add1 s)
|
(add1 s)
|
||||||
s))
|
s))
|
||||||
0 h)))
|
0 h)))
|
||||||
|
|
||||||
(pdefine: (a) (-heap . [xs : a *]) : (Heap a)
|
|
||||||
(list->heap xs))
|
|
||||||
|
|
||||||
|
(pdefine: (a) (-heap . [xs : a *]) : (Heap a)
|
||||||
|
(list->heap xs))
|
||||||
|
|
||||||
|
|
||||||
(define: list->heap : (All (a) (case-lambda (comparator (list-of a) -> (Heap a)) ((list-of a) -> (Heap a))))
|
(define: list->heap : (All (a) (case-lambda (comparator (list-of a) -> (Heap a)) ((list-of a) -> (Heap a))))
|
||||||
; time: O(n)
|
; time: O(n)
|
||||||
(pcase-lambda: (a)
|
(pcase-lambda: (a)
|
||||||
|
@ -222,7 +222,7 @@
|
||||||
(cond
|
(cond
|
||||||
[(or (null? hs)
|
[(or (null? hs)
|
||||||
(null? (cdr hs))) hs]
|
(null? (cdr hs))) hs]
|
||||||
[else
|
[else
|
||||||
(cons (union (car hs) (cadr hs))
|
(cons (union (car hs) (cadr hs))
|
||||||
(merge-pairs (cddr hs)))]))
|
(merge-pairs (cddr hs)))]))
|
||||||
(if (null? hs)
|
(if (null? hs)
|
||||||
|
@ -233,9 +233,9 @@
|
||||||
[(null? hs) (error 'never-happen)]
|
[(null? hs) (error 'never-happen)]
|
||||||
[(null? (cdr hs)) (car hs)]
|
[(null? (cdr hs)) (car hs)]
|
||||||
[else (loop (merge-pairs hs))]))))]))
|
[else (loop (merge-pairs hs))]))))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(pdefine: (a) (insert* [xs : (list-of a)] [h : (Heap a)]) : (Heap a)
|
(pdefine: (a) (insert* [xs : (list-of a)] [h : (Heap a)]) : (Heap a)
|
||||||
(union (list->heap (heap-compare h) xs) h))
|
(union (list->heap (heap-compare h) xs) h))
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@
|
||||||
(pcase-lambda: (a)
|
(pcase-lambda: (a)
|
||||||
[([x : a]) (insert x (#{empty @ a}))]
|
[([x : a]) (insert x (#{empty @ a}))]
|
||||||
[([cmp : comparator] [x : a]) (insert x (make-heap-empty cmp))]))
|
[([cmp : comparator] [x : a]) (insert x (make-heap-empty cmp))]))
|
||||||
|
|
||||||
(pdefine: (a) (size [h : (Heap a)]) : Real
|
(pdefine: (a) (size [h : (Heap a)]) : Real
|
||||||
; NOTE: T(size)=O(n)
|
; NOTE: T(size)=O(n)
|
||||||
(cond
|
(cond
|
||||||
|
@ -257,17 +257,17 @@
|
||||||
[else (+ (size (heap-node-left h))
|
[else (+ (size (heap-node-left h))
|
||||||
1
|
1
|
||||||
(size (heap-node-right h)))]))
|
(size (heap-node-right h)))]))
|
||||||
|
|
||||||
#|
|
#|
|
||||||
;;;
|
;;;
|
||||||
;;; support for srfi-42
|
;;; support for srfi-42
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(define-syntax heap-ec
|
(define-syntax heap-ec
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(heap-ec cmp etc1 etc ...)
|
[(heap-ec cmp etc1 etc ...)
|
||||||
(fold-ec (empty cmp) etc1 etc ... insert)]))
|
(fold-ec (empty cmp) etc1 etc ... insert)]))
|
||||||
|
|
||||||
(define-syntax :heap
|
(define-syntax :heap
|
||||||
(syntax-rules (index)
|
(syntax-rules (index)
|
||||||
((:heap cc var (index i) arg)
|
((:heap cc var (index i) arg)
|
||||||
|
@ -280,7 +280,7 @@
|
||||||
(let ((var (find-min t))))
|
(let ((var (find-min t))))
|
||||||
#t
|
#t
|
||||||
((delete-min t)) ))))
|
((delete-min t)) ))))
|
||||||
|
|
||||||
(define (:heap-dispatch args)
|
(define (:heap-dispatch args)
|
||||||
(cond
|
(cond
|
||||||
[(null? args)
|
[(null? args)
|
||||||
|
@ -289,9 +289,9 @@
|
||||||
(:generator-proc (:heap (car args)))]
|
(:generator-proc (:heap (car args)))]
|
||||||
[else
|
[else
|
||||||
#f]))
|
#f]))
|
||||||
|
|
||||||
(:-dispatch-set!
|
(:-dispatch-set!
|
||||||
(dispatch-union (:-dispatch-ref) :heap-dispatch))
|
(dispatch-union (:-dispatch-ref) :heap-dispatch))
|
||||||
|
|
||||||
|#
|
|#
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
#;(require mzlib/etc)
|
#;(require mzlib/etc)
|
||||||
#;(require "prims.ss")
|
#;(require "prims.ss")
|
||||||
(require mzlib/match
|
(require mzlib/match
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
[(_ [pred expr id rhs] . rest)
|
[(_ [pred expr id rhs] . rest)
|
||||||
(quasisyntax/loc stx
|
(quasisyntax/loc stx
|
||||||
(let ([id expr])
|
(let ([id expr])
|
||||||
(if (pred id)
|
(if (pred id)
|
||||||
rhs
|
rhs
|
||||||
#,(syntax/loc #'rest (cond . rest)))))]
|
#,(syntax/loc #'rest (cond . rest)))))]
|
||||||
[(_ [else . rest]) #'(begin . rest)]
|
[(_ [else . rest]) #'(begin . rest)]
|
||||||
|
@ -41,26 +41,26 @@
|
||||||
(member? a (cdr l)))]))
|
(member? a (cdr l)))]))
|
||||||
|
|
||||||
(define: (rember [a : symbol] [l : (list-of symbol)]) : (list-of symbol)
|
(define: (rember [a : symbol] [l : (list-of symbol)]) : (list-of symbol)
|
||||||
(cond
|
(cond
|
||||||
[(null? l) l]
|
[(null? l) l]
|
||||||
[(eq? (car l) a) (cdr l)]
|
[(eq? (car l) a) (cdr l)]
|
||||||
[else (cons (car l) (rember a (cdr l)))]))
|
[else (cons (car l) (rember a (cdr l)))]))
|
||||||
|
|
||||||
(define: (multisubst [new : symbol] [old : symbol] [lat : (list-of symbol)]) : (list-of symbol)
|
(define: (multisubst [new : symbol] [old : symbol] [lat : (list-of symbol)]) : (list-of symbol)
|
||||||
(cond
|
(cond
|
||||||
[(null? lat) lat]
|
[(null? lat) lat]
|
||||||
[(eq? (car lat) old) (cons new (multisubst new old (cdr lat)))]
|
[(eq? (car lat) old) (cons new (multisubst new old (cdr lat)))]
|
||||||
[else (cons (car lat) (multisubst new old (cdr lat)))]))
|
[else (cons (car lat) (multisubst new old (cdr lat)))]))
|
||||||
|
|
||||||
(define: (tup+ [t1 : (list-of number)] [t2 : (list-of number)]) : (list-of number)
|
(define: (tup+ [t1 : (list-of number)] [t2 : (list-of number)]) : (list-of number)
|
||||||
(cond
|
(cond
|
||||||
[(null? t1) t2]
|
[(null? t1) t2]
|
||||||
[(null? t2) t1]
|
[(null? t2) t1]
|
||||||
[else (cons (+ (car t1) (car t2))
|
[else (cons (+ (car t1) (car t2))
|
||||||
(tup+ (cdr t1) (cdr t2)))]))
|
(tup+ (cdr t1) (cdr t2)))]))
|
||||||
|
|
||||||
(define: (len [l : (list-of top)]) : number
|
(define: (len [l : (list-of top)]) : number
|
||||||
(cond
|
(cond
|
||||||
[(null? l) 0]
|
[(null? l) 0]
|
||||||
[else (add1 (len (cdr l)))]))
|
[else (add1 (len (cdr l)))]))
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@
|
||||||
[else (pick (sub1 n) (cdr lat))]))
|
[else (pick (sub1 n) (cdr lat))]))
|
||||||
|
|
||||||
(define: (no-nums [lat : (list-of atom)]) : (list-of atom)
|
(define: (no-nums [lat : (list-of atom)]) : (list-of atom)
|
||||||
(cond
|
(cond
|
||||||
[(null? lat) lat]
|
[(null? lat) lat]
|
||||||
[(number? (car lat)) (no-nums (cdr lat))]
|
[(number? (car lat)) (no-nums (cdr lat))]
|
||||||
[else (cons (car lat) (no-nums (cdr lat)))]))
|
[else (cons (car lat) (no-nums (cdr lat)))]))
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
(cond [(and (number? a1) (number? a2)) (= a1 a2)]
|
(cond [(and (number? a1) (number? a2)) (= a1 a2)]
|
||||||
[else (eq? a1 a2)]))
|
[else (eq? a1 a2)]))
|
||||||
|
|
||||||
(define: (occur [a : atom] [lat : (list-of atom)]) : number
|
(define: (occur [a : atom] [lat : (list-of atom)]) : number
|
||||||
(cond [(null? lat) 0]
|
(cond [(null? lat) 0]
|
||||||
[(eq? (car lat) a) (add1 (occur a (cdr lat)))]
|
[(eq? (car lat) a) (add1 (occur a (cdr lat)))]
|
||||||
[else (occur a (cdr lat))]))
|
[else (occur a (cdr lat))]))
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
|
|
||||||
;; (atom? (car l)) doesn't do anything - bug in type system
|
;; (atom? (car l)) doesn't do anything - bug in type system
|
||||||
#;(define: (rember* [a : atom] [l : (list-of SExp)]) : (list-of SExp)
|
#;(define: (rember* [a : atom] [l : (list-of SExp)]) : (list-of SExp)
|
||||||
(cond
|
(cond
|
||||||
[(null? l) l]
|
[(null? l) l]
|
||||||
[(atom? (car l))
|
[(atom? (car l))
|
||||||
(cond [(eq? (car l) a) (rember* a (cdr l))]
|
(cond [(eq? (car l) a) (rember* a (cdr l))]
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
[(null? l) l]
|
[(null? l) l]
|
||||||
[else
|
[else
|
||||||
(let ([c (car l)])
|
(let ([c (car l)])
|
||||||
(cond
|
(cond
|
||||||
[(atom? c)
|
[(atom? c)
|
||||||
(cond [(eq? c a) (rember* a (cdr l))]
|
(cond [(eq? c a) (rember* a (cdr l))]
|
||||||
[else (cons c (rember* a (cdr l)))])]
|
[else (cons c (rember* a (cdr l)))])]
|
||||||
|
@ -135,7 +135,7 @@
|
||||||
(insertR* new old (cdr l)))])]
|
(insertR* new old (cdr l)))])]
|
||||||
[else (cons (insertR* new old c)
|
[else (cons (insertR* new old c)
|
||||||
(insertR* new old (cdr l)))]))]))
|
(insertR* new old (cdr l)))]))]))
|
||||||
|
|
||||||
(define: (occur* [a : atom] [l : (list-of SExp)]) : number
|
(define: (occur* [a : atom] [l : (list-of SExp)]) : number
|
||||||
(cond*
|
(cond*
|
||||||
[(null? l) 0]
|
[(null? l) 0]
|
||||||
|
@ -167,7 +167,7 @@
|
||||||
(define-type-alias num-exp (Rec N (U Number (List N (U '+ '* '^) N))))
|
(define-type-alias num-exp (Rec N (U Number (List N (U '+ '* '^) N))))
|
||||||
|
|
||||||
(define: (value [nexp : num-exp]) : number
|
(define: (value [nexp : num-exp]) : number
|
||||||
(cond
|
(cond
|
||||||
[(atom? nexp) nexp]
|
[(atom? nexp) nexp]
|
||||||
[(eq? (car (cdr nexp)) '+)
|
[(eq? (car (cdr nexp)) '+)
|
||||||
(+ (value (car nexp))
|
(+ (value (car nexp))
|
||||||
|
@ -201,20 +201,20 @@
|
||||||
(makeset (multirember (car l) (cdr l))))]))
|
(makeset (multirember (car l) (cdr l))))]))
|
||||||
|
|
||||||
(define: (subset? [set1 : lat] [set2 : lat]) : boolean
|
(define: (subset? [set1 : lat] [set2 : lat]) : boolean
|
||||||
(cond
|
(cond
|
||||||
[(null? set1) #t]
|
[(null? set1) #t]
|
||||||
[(member? (car set1) set2)
|
[(member? (car set1) set2)
|
||||||
(subset? (cdr set1) set2)]
|
(subset? (cdr set1) set2)]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
|
|
||||||
(define: (subset2? [set1 : (list-of atom)] [set2 : (list-of atom)]) : boolean
|
(define: (subset2? [set1 : (list-of atom)] [set2 : (list-of atom)]) : boolean
|
||||||
(cond
|
(cond
|
||||||
[(null? set1) #t]
|
[(null? set1) #t]
|
||||||
[else (and (member? (car set1) set2)
|
[else (and (member? (car set1) set2)
|
||||||
(subset? (cdr set1) set2))]))
|
(subset? (cdr set1) set2))]))
|
||||||
|
|
||||||
(define: (intersect? [set1 : (list-of atom)] [set2 : (list-of atom)]) : boolean
|
(define: (intersect? [set1 : (list-of atom)] [set2 : (list-of atom)]) : boolean
|
||||||
(cond
|
(cond
|
||||||
[(null? set1) #t]
|
[(null? set1) #t]
|
||||||
[else (or (member? (car set1) set2)
|
[else (or (member? (car set1) set2)
|
||||||
(intersect? (cdr set1) set2))]))
|
(intersect? (cdr set1) set2))]))
|
||||||
|
@ -269,11 +269,11 @@
|
||||||
|
|
||||||
|
|
||||||
(define: (seqR [new : atom] [old : atom] [l : (list-of atom)]) : (list-of atom)
|
(define: (seqR [new : atom] [old : atom] [l : (list-of atom)]) : (list-of atom)
|
||||||
(cons old (cons new l)))
|
(cons old (cons new l)))
|
||||||
|
|
||||||
(define: (insertR-g [seq : (atom atom lat -> lat)]
|
(define: (insertR-g [seq : (atom atom lat -> lat)]
|
||||||
[test? : (atom atom -> boolean)]
|
[test? : (atom atom -> boolean)]
|
||||||
[new : atom] [old : atom] [l : (list-of atom)])
|
[new : atom] [old : atom] [l : (list-of atom)])
|
||||||
: (list-of atom)
|
: (list-of atom)
|
||||||
(cond
|
(cond
|
||||||
[(null? l) l]
|
[(null? l) l]
|
||||||
|
@ -282,9 +282,9 @@
|
||||||
[else (cons (car l)
|
[else (cons (car l)
|
||||||
(insertR-g seq test? new old (cdr l)))]))
|
(insertR-g seq test? new old (cdr l)))]))
|
||||||
|
|
||||||
(define: (insertR-g-curry [seq : (atom atom (list-of atom) -> (list-of atom))])
|
(define: (insertR-g-curry [seq : (atom atom (list-of atom) -> (list-of atom))])
|
||||||
: ((atom atom -> boolean) atom atom (list-of atom) -> (list-of atom))
|
: ((atom atom -> boolean) atom atom (list-of atom) -> (list-of atom))
|
||||||
(lambda: ([test? : (atom atom -> boolean)]
|
(lambda: ([test? : (atom atom -> boolean)]
|
||||||
[new : atom] [old : atom] [l : (list-of atom)])
|
[new : atom] [old : atom] [l : (list-of atom)])
|
||||||
(cond
|
(cond
|
||||||
[(null? l) l]
|
[(null? l) l]
|
||||||
|
@ -368,7 +368,7 @@
|
||||||
(define-type-alias table (list-of entry))
|
(define-type-alias table (list-of entry))
|
||||||
|
|
||||||
|
|
||||||
(define: (new-entry [keys : (list-of atom)]
|
(define: (new-entry [keys : (list-of atom)]
|
||||||
[vals : (list-of atom)]) : entry
|
[vals : (list-of atom)]) : entry
|
||||||
(cons keys (cons vals empty-atom)))
|
(cons keys (cons vals empty-atom)))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(: f ((U Number #f) (cons Any Any) -> Number))
|
(: f ((U Number #f) (cons Any Any) -> Number))
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
(define: N : Positive-Fixnum 512)
|
(define: N : Positive-Fixnum 512)
|
||||||
(: mandelbrot-point : Integer Integer -> Integer)
|
(: mandelbrot-point : Integer Integer -> Integer)
|
||||||
(define (mandelbrot-point x y)
|
(define (mandelbrot-point x y)
|
||||||
(define c
|
(define c
|
||||||
(+ (- (/ (* 2.0 (->fl x)) N) 1.5)
|
(+ (- (/ (* 2.0 (->fl x)) N) 1.5)
|
||||||
(* 0.0+1.0i (- (/ (* 2.0 (->fl y)) N) 1.0))))
|
(* 0.0+1.0i (- (/ (* 2.0 (->fl y)) N) 1.0))))
|
||||||
(let loop ((i 0) (z 0.0+0.0i))
|
(let loop ((i 0) (z 0.0+0.0i))
|
||||||
|
|
|
@ -16,25 +16,25 @@
|
||||||
(display (my-even? 12)))
|
(display (my-even? 12)))
|
||||||
|
|
||||||
(module date typed-scheme
|
(module date typed-scheme
|
||||||
|
|
||||||
(define-typed-struct my-date ([day : Number] [month : String] [year : Number]))
|
(define-typed-struct my-date ([day : Number] [month : String] [year : Number]))
|
||||||
|
|
||||||
(define: (format-date [d : my-date]) : String
|
(define: (format-date [d : my-date]) : String
|
||||||
(format "Today is day ~a of ~a in the year ~a" (my-date-day d) (my-date-month d) (my-date-year d)))
|
(format "Today is day ~a of ~a in the year ~a" (my-date-day d) (my-date-month d) (my-date-year d)))
|
||||||
|
|
||||||
(display (format-date (make-my-date 28 "November" 2006)))
|
(display (format-date (make-my-date 28 "November" 2006)))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(module tree typed-scheme
|
(module tree typed-scheme
|
||||||
(define-typed-struct leaf ([val : Number]))
|
(define-typed-struct leaf ([val : Number]))
|
||||||
(define-typed-struct node ([left : (Un node leaf)] [right : (Un node leaf)]))
|
(define-typed-struct node ([left : (Un node leaf)] [right : (Un node leaf)]))
|
||||||
|
|
||||||
(define: (tree-height [t : (Un node leaf)]) : Integer
|
(define: (tree-height [t : (Un node leaf)]) : Integer
|
||||||
(cond [(leaf? t) 1]
|
(cond [(leaf? t) 1]
|
||||||
[else (max (tree-height (node-left t))
|
[else (max (tree-height (node-left t))
|
||||||
(tree-height (node-right t)))]))
|
(tree-height (node-right t)))]))
|
||||||
|
|
||||||
(define: (tree-sum [t : (Un node leaf)]) : Number
|
(define: (tree-sum [t : (Un node leaf)]) : Number
|
||||||
(cond [(leaf? t) (leaf-val t)]
|
(cond [(leaf? t) (leaf-val t)]
|
||||||
[else (+ (tree-sum (node-left t))
|
[else (+ (tree-sum (node-left t))
|
||||||
|
@ -43,14 +43,14 @@
|
||||||
(module tree typed-scheme
|
(module tree typed-scheme
|
||||||
(define-typed-struct leaf ([val : Number]))
|
(define-typed-struct leaf ([val : Number]))
|
||||||
(define-typed-struct node ([left : (Un node leaf)] [right : (Un node leaf)]))
|
(define-typed-struct node ([left : (Un node leaf)] [right : (Un node leaf)]))
|
||||||
|
|
||||||
(define-type-alias tree (Un node leaf))
|
(define-type-alias tree (Un node leaf))
|
||||||
|
|
||||||
(define: (tree-height [t : tree]) : Integer
|
(define: (tree-height [t : tree]) : Integer
|
||||||
(cond [(leaf? t) 1]
|
(cond [(leaf? t) 1]
|
||||||
[else (max (tree-height (node-left t))
|
[else (max (tree-height (node-left t))
|
||||||
(tree-height (node-right t)))]))
|
(tree-height (node-right t)))]))
|
||||||
|
|
||||||
(define: (tree-sum [t : tree]) : Number
|
(define: (tree-sum [t : tree]) : Number
|
||||||
(cond [(leaf? t) (leaf-val t)]
|
(cond [(leaf? t) (leaf-val t)]
|
||||||
[else (+ (tree-sum (node-left t))
|
[else (+ (tree-sum (node-left t))
|
||||||
|
@ -64,9 +64,9 @@
|
||||||
(module maybe typed-scheme
|
(module maybe typed-scheme
|
||||||
(define-typed-struct Nothing ())
|
(define-typed-struct Nothing ())
|
||||||
(define-typed-struct (a) Just ([v : a]))
|
(define-typed-struct (a) Just ([v : a]))
|
||||||
|
|
||||||
(define-type-alias (Maybe a) (Un Nothing (Just a)))
|
(define-type-alias (Maybe a) (Un Nothing (Just a)))
|
||||||
|
|
||||||
(define: (find [v : Number] [l : (Listof Number)]) : (Maybe Number)
|
(define: (find [v : Number] [l : (Listof Number)]) : (Maybe Number)
|
||||||
(cond [(null? l) (make-Nothing)]
|
(cond [(null? l) (make-Nothing)]
|
||||||
[(= v (car l)) (make-Just v)]
|
[(= v (car l)) (make-Just v)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(map add1 #{(list 1 2 3) :: (Listof Integer)})
|
(map add1 #{(list 1 2 3) :: (Listof Integer)})
|
||||||
(map add1 #{(list 1 2 3) :: (Listof Number)})
|
(map add1 #{(list 1 2 3) :: (Listof Number)})
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
x
|
x
|
||||||
'x)
|
'x)
|
||||||
(U 'x 'y))
|
(U 'x 'y))
|
||||||
|
|
||||||
(ann
|
(ann
|
||||||
(if (memv x '(x y))
|
(if (memv x '(x y))
|
||||||
x
|
x
|
||||||
'x)
|
'x)
|
||||||
(U 'x 'y))
|
(U 'x 'y))
|
||||||
|
|
||||||
(if (memq x '(x y))
|
(if (memq x '(x y))
|
||||||
x
|
x
|
||||||
'x))
|
'x))
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#;(require "../list.scm"
|
#;(require "../list.scm"
|
||||||
"../etc.ss")
|
"../etc.ss")
|
||||||
(require/typed apply-to-scheme-files
|
(require/typed apply-to-scheme-files
|
||||||
((Path -> (Listof (Listof (U #f (Listof (U Real #f))))))
|
((Path -> (Listof (Listof (U #f (Listof (U Real #f))))))
|
||||||
Path
|
Path
|
||||||
-> (Listof (U #f (Listof (Listof ( U #f (Listof (U Real #f)))))))) "foldo.rkt")
|
-> (Listof (U #f (Listof (Listof ( U #f (Listof (U Real #f)))))))) "foldo.rkt")
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
(define-type-alias NumB (U boolean number))
|
(define-type-alias NumB (U boolean number))
|
||||||
;;C is either Sexpr or Listof Sepr
|
;;C is either Sexpr or Listof Sepr
|
||||||
;;X = (Listof (U number #f)) - not needed as a parameter
|
;;X = (Listof (U number #f)) - not needed as a parameter
|
||||||
(define-type-alias (Unit X C) ((C -> X) -> (Path -> (Listof (U #f X)))))
|
(define-type-alias (Unit X C) ((C -> X) -> (Path -> (Listof (U #f X)))))
|
||||||
|
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; CONFIG
|
;; CONFIG
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
;; in mean cannot be explained by chance.
|
;; in mean cannot be explained by chance.
|
||||||
(define: (t-test [seqA : (Listof Real)] [seqB : (Listof Real)]) : Real
|
(define: (t-test [seqA : (Listof Real)] [seqB : (Listof Real)]) : Real
|
||||||
(manual-t-test
|
(manual-t-test
|
||||||
(avg seqA) (avg seqB)
|
(avg seqA) (avg seqB)
|
||||||
(variance seqA) (variance seqB)
|
(variance seqA) (variance seqB)
|
||||||
(length seqA) (length seqB)))
|
(length seqA) (length seqB)))
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
;; be explained by chance. higher numbers means higher confidence
|
;; be explained by chance. higher numbers means higher confidence
|
||||||
;; that they cannot.
|
;; that they cannot.
|
||||||
(define: (chi-square [seqA : (Listof number)] [seqB : (Listof number)]) : number
|
(define: (chi-square [seqA : (Listof number)] [seqB : (Listof number)]) : number
|
||||||
(with-handlers ([exn:fail? (lambda: ([e : str]) +nan.0)])
|
(with-handlers ([exn:fail? (lambda: ([e : str]) +nan.0)])
|
||||||
(let* ([ct-a (length seqA)]
|
(let* ([ct-a (length seqA)]
|
||||||
[ct-b (length seqB)]
|
[ct-b (length seqB)]
|
||||||
[total-subjects (+ ct-a ct-b)]
|
[total-subjects (+ ct-a ct-b)]
|
||||||
|
@ -86,8 +86,8 @@
|
||||||
(,a-misses ,b-misses))]
|
(,a-misses ,b-misses))]
|
||||||
[expected (lambda: ([i : Integer] [j : Integer])
|
[expected (lambda: ([i : Integer] [j : Integer])
|
||||||
(/ (* (row-total i table) (col-total j table)) total-subjects))])
|
(/ (* (row-total i table) (col-total j table)) total-subjects))])
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(table-sum
|
(table-sum
|
||||||
(lambda: ([i : Integer] [j : Integer])
|
(lambda: ([i : Integer] [j : Integer])
|
||||||
(/ (sqr (- (expected i j) (table-ref i j table))) (expected i j)))
|
(/ (sqr (- (expected i j) (table-ref i j table))) (expected i j)))
|
||||||
table)))))
|
table)))))
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
;; UNITS OF MEASUREMENT IMPLEMENTATIONS
|
;; UNITS OF MEASUREMENT IMPLEMENTATIONS
|
||||||
|
|
||||||
;; per-module : path ((listof expr) -> (number | #f)) -> (path -> (listof (number | #f))) === Unit P
|
;; per-module : path ((listof expr) -> (number | #f)) -> (path -> (listof (number | #f))) === Unit P
|
||||||
(pdefine: (X) (per-module [f : ((Listof Sexpr) -> X )]) : (Path -> (cons (U #f X) '()))
|
(pdefine: (X) (per-module [f : ((Listof Sexpr) -> X )]) : (Path -> (cons (U #f X) '()))
|
||||||
(lambda: ([path : Path])
|
(lambda: ([path : Path])
|
||||||
(with-handlers ([exn:fail:read? (lambda: ([e : Void]) (list #f))]) ;; with handler
|
(with-handlers ([exn:fail:read? (lambda: ([e : Void]) (list #f))]) ;; with handler
|
||||||
(let ([initial-sexp (with-input-from-file path read)])
|
(let ([initial-sexp (with-input-from-file path read)])
|
||||||
|
@ -108,10 +108,10 @@
|
||||||
|
|
||||||
;; per-module-top-level-expression : path (expr -> (number | #f)) -> (path -> (listof (number | #f)))
|
;; per-module-top-level-expression : path (expr -> (number | #f)) -> (path -> (listof (number | #f)))
|
||||||
(define: (per-module-top-level-expression [f : (Sexpr -> (Listof NumF))] ) : ( Path -> (Listof (U #f (Listof NumF))))
|
(define: (per-module-top-level-expression [f : (Sexpr -> (Listof NumF))] ) : ( Path -> (Listof (U #f (Listof NumF))))
|
||||||
(let ([calc (per-module (lambda: ([exprs : (Listof Sexpr)]) (map f exprs)))])
|
(let ([calc (per-module (lambda: ([exprs : (Listof Sexpr)]) (map f exprs)))])
|
||||||
(lambda: ([p : Path]) (let* ([r (calc p)]
|
(lambda: ([p : Path]) (let* ([r (calc p)]
|
||||||
[carr (car r)]) ;;carr added
|
[carr (car r)]) ;;carr added
|
||||||
(if carr carr
|
(if carr carr
|
||||||
(list carr)))))) ;; list carr instead of r
|
(list carr)))))) ;; list carr instead of r
|
||||||
|
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; setbang counts
|
;; setbang counts
|
||||||
|
|
||||||
(define-type-alias (IList e) (mu x (Un e '() (cons e x))))
|
(define-type-alias (IList e) (mu x (Un e '() (cons e x))))
|
||||||
|
|
||||||
;; count-setbangs/ilist : ((ilistof expr) -> number)
|
;; count-setbangs/ilist : ((ilistof expr) -> number)
|
||||||
(define: (count-setbangs/ilist [exprs : (Listof Any)]) : number
|
(define: (count-setbangs/ilist [exprs : (Listof Any)]) : number
|
||||||
|
@ -148,12 +148,12 @@
|
||||||
(define: (count-setbangs/expr [expr : Any]) : number
|
(define: (count-setbangs/expr [expr : Any]) : number
|
||||||
(match expr
|
(match expr
|
||||||
[`(,(? setbang?) . ,rest ) ;(,(? setbang?) ,rest ...)
|
[`(,(? setbang?) . ,rest ) ;(,(? setbang?) ,rest ...)
|
||||||
(if (list? rest)
|
(if (list? rest)
|
||||||
(+ 1 (count-setbangs/ilist rest))
|
(+ 1 (count-setbangs/ilist rest))
|
||||||
0)] ;; mostly occurs in syntax patterns
|
0)] ;; mostly occurs in syntax patterns
|
||||||
[('quote _) 0]
|
[('quote _) 0]
|
||||||
[('quasiquote _) 0] ; undercount potentially, but how many `,(set! ...)'s can there be?
|
[('quasiquote _) 0] ; undercount potentially, but how many `,(set! ...)'s can there be?
|
||||||
[`(,e1 . ,e2)
|
[`(,e1 . ,e2)
|
||||||
(if (list? expr)
|
(if (list? expr)
|
||||||
(count-setbangs/ilist expr)
|
(count-setbangs/ilist expr)
|
||||||
(error " l" expr ))] ;;FIXME - do something intelligent here
|
(error " l" expr ))] ;;FIXME - do something intelligent here
|
||||||
|
@ -167,7 +167,7 @@
|
||||||
;; count-fns
|
;; count-fns
|
||||||
(define: (count-fns-with-setbangs [exprs : (Listof Sexpr)]) : number
|
(define: (count-fns-with-setbangs [exprs : (Listof Sexpr)]) : number
|
||||||
(apply + (map (lambda: ([e : Sexpr]) (if (= (count-setbangs/expr e) 0) 0 1)) exprs)))
|
(apply + (map (lambda: ([e : Sexpr]) (if (= (count-setbangs/expr e) 0) 0 1)) exprs)))
|
||||||
(define: (module-has-setbangs? [exprs : (Listof Sexpr)]) : Boolean
|
(define: (module-has-setbangs? [exprs : (Listof Sexpr)]) : Boolean
|
||||||
(ormap expr-uses-setbangs? exprs))
|
(ormap expr-uses-setbangs? exprs))
|
||||||
(define: (expr-uses-setbangs? [expr : Sexpr]) : Boolean
|
(define: (expr-uses-setbangs? [expr : Sexpr]) : Boolean
|
||||||
(not (= (count-setbangs/expr expr) 0)))
|
(not (= (count-setbangs/expr expr) 0)))
|
||||||
|
@ -180,10 +180,10 @@
|
||||||
(* (/ set!s atoms) 1000.0))))
|
(* (/ set!s atoms) 1000.0))))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; contracts
|
;; contracts
|
||||||
|
|
||||||
|
|
||||||
(define: (uses-contracts [exprs : (Listof Sexpr)]) : Boolean
|
(define: (uses-contracts [exprs : (Listof Sexpr)]) : Boolean
|
||||||
(ormap (lambda: ([e : Sexpr])
|
(ormap (lambda: ([e : Sexpr])
|
||||||
(match e
|
(match e
|
||||||
[`(provide/contract . ,_) #t]
|
[`(provide/contract . ,_) #t]
|
||||||
|
@ -195,9 +195,9 @@
|
||||||
(lambda: ([t : Sexpr] [r : number])
|
(lambda: ([t : Sexpr] [r : number])
|
||||||
(match t
|
(match t
|
||||||
;; FIXME match ...
|
;; FIXME match ...
|
||||||
[`(provide/contract . ,p ) ;(provide/contract ,p ...)
|
[`(provide/contract . ,p ) ;(provide/contract ,p ...)
|
||||||
(if (list? p)
|
(if (list? p)
|
||||||
(+ (length p) r)
|
(+ (length p) r)
|
||||||
r)] ;; extra case added
|
r)] ;; extra case added
|
||||||
[_ r]))
|
[_ r]))
|
||||||
0
|
0
|
||||||
|
@ -208,10 +208,10 @@
|
||||||
(foldl
|
(foldl
|
||||||
(lambda: ([t : Sexpr] [r : number])
|
(lambda: ([t : Sexpr] [r : number])
|
||||||
(match t
|
(match t
|
||||||
[`(provide . ,p ) ;(provide ,p ...)
|
[`(provide . ,p ) ;(provide ,p ...)
|
||||||
(if (list? p)
|
(if (list? p)
|
||||||
(+ (length p) r)
|
(+ (length p) r)
|
||||||
r)]
|
r)]
|
||||||
[_ r]))
|
[_ r]))
|
||||||
0
|
0
|
||||||
exprs))
|
exprs))
|
||||||
|
@ -222,11 +222,11 @@
|
||||||
(define: (number-of-macro-definitions [expr : Sexpr]) : number
|
(define: (number-of-macro-definitions [expr : Sexpr]) : number
|
||||||
(match expr
|
(match expr
|
||||||
[`(define-syntax ,_ ...) 1]
|
[`(define-syntax ,_ ...) 1]
|
||||||
[`(define-syntaxes (,s . ,r ). ,_ ) ;`(define-syntaxes (,s ...) ,_ ...)
|
[`(define-syntaxes (,s . ,r ). ,_ ) ;`(define-syntaxes (,s ...) ,_ ...)
|
||||||
(if (and (list? expr)(list? r))
|
(if (and (list? expr)(list? r))
|
||||||
(length (cons s r));;s -> cadr expr
|
(length (cons s r));;s -> cadr expr
|
||||||
(error "corrupted file"))]
|
(error "corrupted file"))]
|
||||||
[`(define-syntax-set (,s . ,r) . ,_ ) ;(define-syntax-set (,s ...) ,_ ...)
|
[`(define-syntax-set (,s . ,r) . ,_ ) ;(define-syntax-set (,s ...) ,_ ...)
|
||||||
(if (and (list? expr) (list? r))
|
(if (and (list? expr) (list? r))
|
||||||
(length (cons s r))
|
(length (cons s r))
|
||||||
(error "corrupted file"))]
|
(error "corrupted file"))]
|
||||||
|
@ -270,14 +270,14 @@
|
||||||
(define-type-alias Table (Listof (Listof Real)))
|
(define-type-alias Table (Listof (Listof Real)))
|
||||||
(define-type-alias Atom-display (cons Symbol (Listof Real)))
|
(define-type-alias Atom-display (cons Symbol (Listof Real)))
|
||||||
|
|
||||||
(define: (standard-display [name : Symbol]
|
(define: (standard-display [name : Symbol]
|
||||||
[summarize : ((Listof number) -> number)]
|
[summarize : ((Listof number) -> number)]
|
||||||
[significance-test : ((Listof number)(Listof number) -> number)])
|
[significance-test : ((Listof number)(Listof number) -> number)])
|
||||||
: ((Listof NumF) (Listof NumF) -> Atom-display)
|
: ((Listof NumF) (Listof NumF) -> Atom-display)
|
||||||
;; FIXME - use lambda instead of (define ((
|
;; FIXME - use lambda instead of (define ((
|
||||||
(lambda: ([seqA : (Listof NumF)] [seqB : (Listof NumF)])
|
(lambda: ([seqA : (Listof NumF)] [seqB : (Listof NumF)])
|
||||||
(let ([clean-seqA (nonfalses seqA)]
|
(let ([clean-seqA (nonfalses seqA)]
|
||||||
[clean-seqB (nonfalses seqB)])
|
[clean-seqB (nonfalses seqB)])
|
||||||
(list name (summarize clean-seqA) (summarize clean-seqB) (significance-test clean-seqA clean-seqB)))))
|
(list name (summarize clean-seqA) (summarize clean-seqB) (significance-test clean-seqA clean-seqB)))))
|
||||||
|
|
||||||
(pdefine: (c) (interval [u : (Unit (Listof NumF) c)]
|
(pdefine: (c) (interval [u : (Unit (Listof NumF) c)]
|
||||||
|
@ -292,20 +292,20 @@
|
||||||
: (Metric Atom-display c NumF)
|
: (Metric Atom-display c NumF)
|
||||||
(make-metric u (lambda: ([es : c]) #{(if (compute es) 1 0) :: NumF}) (standard-display name avg chi-square)))
|
(make-metric u (lambda: ([es : c]) #{(if (compute es) 1 0) :: NumF}) (standard-display name avg chi-square)))
|
||||||
|
|
||||||
(pdefine: (c) (combine-metrics [ms : (Listof (Metric Atom-display c NumF))])
|
(pdefine: (c) (combine-metrics [ms : (Listof (Metric Atom-display c NumF))])
|
||||||
: (Metric (Listof Atom-display) c (Listof NumF))
|
: (Metric (Listof Atom-display) c (Listof NumF))
|
||||||
(let ([u (metric-analysis-unit (car ms))])
|
(let ([u (metric-analysis-unit (car ms))])
|
||||||
;; This test now redundant b/c of typechecking
|
;; This test now redundant b/c of typechecking
|
||||||
(unless (andmap (lambda: ([m : (Metric Atom-display c NumF) ]) (eq? u (metric-analysis-unit m))) ms)
|
(unless (andmap (lambda: ([m : (Metric Atom-display c NumF) ]) (eq? u (metric-analysis-unit m))) ms)
|
||||||
(error 'combine-metrics "all combined metrics must operate on the same unit of analysis"))
|
(error 'combine-metrics "all combined metrics must operate on the same unit of analysis"))
|
||||||
|
|
||||||
(make-metric
|
(make-metric
|
||||||
u
|
u
|
||||||
(lambda: ([exprs : c] ) (map (lambda: ([m : (Metric Atom-display c NumF)]) ((metric-computation m) exprs)) ms))
|
(lambda: ([exprs : c] ) (map (lambda: ([m : (Metric Atom-display c NumF)]) ((metric-computation m) exprs)) ms))
|
||||||
(lambda: ([seqA : (Listof (Listof NumF))] [seqB : (Listof (Listof NumF))])
|
(lambda: ([seqA : (Listof (Listof NumF))] [seqB : (Listof (Listof NumF))])
|
||||||
(map (lambda: ([m : (Metric Atom-display c NumF)]
|
(map (lambda: ([m : (Metric Atom-display c NumF)]
|
||||||
[sA : (Listof NumF)]
|
[sA : (Listof NumF)]
|
||||||
[sB : (Listof NumF)])
|
[sB : (Listof NumF)])
|
||||||
((metric->display m) sA sB)) ms (pivot seqA) (pivot seqB))))))
|
((metric->display m) sA sB)) ms (pivot seqA) (pivot seqB))))))
|
||||||
|
|
||||||
;; FIXME - should go in helper file
|
;; FIXME - should go in helper file
|
||||||
|
@ -315,13 +315,13 @@
|
||||||
(if (null? lst)
|
(if (null? lst)
|
||||||
'()
|
'()
|
||||||
(let ([x (car lst)])
|
(let ([x (car lst)])
|
||||||
(if x
|
(if x
|
||||||
(cons x (loop (cdr lst)))
|
(cons x (loop (cdr lst)))
|
||||||
(loop (cdr lst)))))))
|
(loop (cdr lst)))))))
|
||||||
|
|
||||||
(define: (avg [l : (Listof number)]) : number
|
(define: (avg [l : (Listof number)]) : number
|
||||||
(/ (exact->inexact (apply + l)) (length l)))
|
(/ (exact->inexact (apply + l)) (length l)))
|
||||||
(define: (avg* [l : (Listof number)]) : number
|
(define: (avg* [l : (Listof number)]) : number
|
||||||
(avg (nonfalses l)))
|
(avg (nonfalses l)))
|
||||||
|
|
||||||
(require (for-syntax scheme/base))
|
(require (for-syntax scheme/base))
|
||||||
|
@ -333,7 +333,7 @@
|
||||||
[n (syntax->list #'(name ...))]
|
[n (syntax->list #'(name ...))]
|
||||||
[f (syntax->list #'(fn ...))])
|
[f (syntax->list #'(fn ...))])
|
||||||
(quasisyntax/loc k (#,k u '#,n #,f)))])
|
(quasisyntax/loc k (#,k u '#,n #,f)))])
|
||||||
(syntax/loc
|
(syntax/loc
|
||||||
stx
|
stx
|
||||||
(begin
|
(begin
|
||||||
(define: u : ((type -> (Listof NumF)) -> (Path -> (Listof (U #f(Listof NumF))))) unit-of-analysis )
|
(define: u : ((type -> (Listof NumF)) -> (Path -> (Listof (U #f(Listof NumF))))) unit-of-analysis )
|
||||||
|
@ -348,14 +348,14 @@
|
||||||
(uses-setbang?/mod count module-has-setbangs?)
|
(uses-setbang?/mod count module-has-setbangs?)
|
||||||
(uses-contracts? count uses-contracts)
|
(uses-contracts? count uses-contracts)
|
||||||
(number-of-contracts interval contracted-provides)
|
(number-of-contracts interval contracted-provides)
|
||||||
(num-uncontracted-provides interval uncontracted-provides)
|
(num-uncontracted-provides interval uncontracted-provides)
|
||||||
(number-of-macro-defs interval num-of-define-syntax)
|
(number-of-macro-defs interval num-of-define-syntax)
|
||||||
(maximum-num-atoms interval max-atoms)
|
(maximum-num-atoms interval max-atoms)
|
||||||
(average-num-atoms interval avg-atoms)
|
(average-num-atoms interval avg-atoms)
|
||||||
(total-num-atoms/mod interval total-atoms)
|
(total-num-atoms/mod interval total-atoms)
|
||||||
(set!s-per-1000-atoms interval setbangs-per-1000-atoms))
|
(set!s-per-1000-atoms interval setbangs-per-1000-atoms))
|
||||||
|
|
||||||
(define-metrics tl-expr-metrics per-module-top-level-expression Sexpr
|
(define-metrics tl-expr-metrics per-module-top-level-expression Sexpr
|
||||||
(uses-setbang?/fn count expr-uses-setbangs?)
|
(uses-setbang?/fn count expr-uses-setbangs?)
|
||||||
(number-of-setbangs/fn interval count-setbangs/expr)
|
(number-of-setbangs/fn interval count-setbangs/expr)
|
||||||
(total-num-atoms/fn interval atoms))
|
(total-num-atoms/fn interval atoms))
|
||||||
|
@ -367,16 +367,16 @@
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; EXPERIMENT RUNNING
|
;; EXPERIMENT RUNNING
|
||||||
|
|
||||||
;; FIXME - everything in untyped file (foldo.ss) b/c fold-files has terrible api
|
;; FIXME - everything in untyped file (foldo.ss) b/c fold-files has terrible api
|
||||||
#;(define-syntax (define-excluder stx)
|
#;(define-syntax (define-excluder stx)
|
||||||
|
|
||||||
(define (path->clause c)
|
(define (path->clause c)
|
||||||
(syntax-case c ()
|
(syntax-case c ()
|
||||||
[(item ...)
|
[(item ...)
|
||||||
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
||||||
[item
|
[item
|
||||||
#`[`(item) #t]]))
|
#`[`(item) #t]]))
|
||||||
|
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ name path ...)
|
[(_ name path ...)
|
||||||
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
||||||
|
@ -386,7 +386,7 @@
|
||||||
match-clause ...
|
match-clause ...
|
||||||
[_ #f]))))]))
|
[_ #f]))))]))
|
||||||
|
|
||||||
#;(define-excluder default-excluder
|
#;(define-excluder default-excluder
|
||||||
"compiled" ".svn" #;("collects" "drscheme") #;("collects" "framework"))
|
"compiled" ".svn" #;("collects" "drscheme") #;("collects" "framework"))
|
||||||
|
|
||||||
#;(define: exclude-directory? : (Parameter (Path -> Any)) (make-parameter default-excluder))
|
#;(define: exclude-directory? : (Parameter (Path -> Any)) (make-parameter default-excluder))
|
||||||
|
@ -395,10 +395,10 @@
|
||||||
;; apply-to-scheme-files: (path[file] -> X) path[directory] -> (listof X)
|
;; apply-to-scheme-files: (path[file] -> X) path[directory] -> (listof X)
|
||||||
;; applies the given function to each .ss or .scm file in the given directory
|
;; applies the given function to each .ss or .scm file in the given directory
|
||||||
;; hierarchy; returns all results in a list
|
;; hierarchy; returns all results in a list
|
||||||
#;(define: (apply-to-scheme-files [f : (Path -> (Listof(Listof(Listof NumF))))]
|
#;(define: (apply-to-scheme-files [f : (Path -> (Listof(Listof(Listof NumF))))]
|
||||||
[root : Path])
|
[root : Path])
|
||||||
: (Listof (Listof(Listof(Listof NumF)))) ;;FOLD-FILES
|
: (Listof (Listof(Listof(Listof NumF)))) ;;FOLD-FILES
|
||||||
|
|
||||||
(fold-files
|
(fold-files
|
||||||
(lambda: ([path : Path] [kind : Symbol]
|
(lambda: ([path : Path] [kind : Symbol]
|
||||||
[acc : (Listof (Listof(Listof(Listof NumF))))])
|
[acc : (Listof (Listof(Listof(Listof NumF))))])
|
||||||
|
@ -413,10 +413,10 @@
|
||||||
#;(cons resl acc) (values (cons resl acc) #t) ;;values added
|
#;(cons resl acc) (values (cons resl acc) #t) ;;values added
|
||||||
#;acc (values acc #t)))]
|
#;acc (values acc #t)))]
|
||||||
[else #;acc (values acc #t)]))]
|
[else #;acc (values acc #t)]))]
|
||||||
[(dir)
|
[(dir)
|
||||||
(let* ([p (normalize-path path root)])
|
(let* ([p (normalize-path path root)])
|
||||||
(if ((exclude-directory?) p)
|
(if ((exclude-directory?) p)
|
||||||
#; acc (values acc #f)
|
#; acc (values acc #f)
|
||||||
#;acc (values acc #t)))] ;; values added
|
#;acc (values acc #t)))] ;; values added
|
||||||
[(link) #;acc (values acc #t)]
|
[(link) #;acc (values acc #t)]
|
||||||
[else (error "never happen")])) ;;error added
|
[else (error "never happen")])) ;;error added
|
||||||
|
@ -430,23 +430,23 @@
|
||||||
;; get-sequences : (listof 'a metric) path -> (listof (listof 'a))
|
;; get-sequences : (listof 'a metric) path -> (listof (listof 'a))
|
||||||
|
|
||||||
(pdefine: (b c) (get-sequences [metrics : (Listof (U (Metric b c (Listof NumF))))]
|
(pdefine: (b c) (get-sequences [metrics : (Listof (U (Metric b c (Listof NumF))))]
|
||||||
[path : Path])
|
[path : Path])
|
||||||
: (Listof (Listof (Listof NumF)))
|
: (Listof (Listof (Listof NumF)))
|
||||||
(let* ([metric-fns ; : (Listof (Path -> (Listof (U #f(Listof NumF)))))
|
(let* ([metric-fns ; : (Listof (Path -> (Listof (U #f(Listof NumF)))))
|
||||||
(map (lambda: ([m : (Metric b c (Listof NumF))])
|
(map (lambda: ([m : (Metric b c (Listof NumF))])
|
||||||
((metric-analysis-unit m)
|
((metric-analysis-unit m)
|
||||||
(metric-computation m))) metrics)]
|
(metric-computation m))) metrics)]
|
||||||
[#{result-seqs : (Listof (U #f (Listof (Listof ( U #f (Listof NumF))))))}
|
[#{result-seqs : (Listof (U #f (Listof (Listof ( U #f (Listof NumF))))))}
|
||||||
(apply-to-scheme-files
|
(apply-to-scheme-files
|
||||||
(lambda: ([file : Path])
|
(lambda: ([file : Path])
|
||||||
(map (lambda: ([fn : (Path -> (Listof (U #f (Listof NumF))))]) (fn file)) metric-fns)) path)])
|
(map (lambda: ([fn : (Path -> (Listof (U #f (Listof NumF))))]) (fn file)) metric-fns)) path)])
|
||||||
(map (lambda: ([l : (Listof(Listof (Option (Listof NumF))))])
|
(map (lambda: ([l : (Listof(Listof (Option (Listof NumF))))])
|
||||||
;; FIXME - problem with inference and ordering
|
;; FIXME - problem with inference and ordering
|
||||||
(nonfalses (apply append l)))
|
(nonfalses (apply append l)))
|
||||||
(pivot (nonfalses result-seqs)))))
|
(pivot (nonfalses result-seqs)))))
|
||||||
|
|
||||||
;; compare* : (listof metric) -> (listof result)
|
;; compare* : (listof metric) -> (listof result)
|
||||||
(: compare* (All (b c)
|
(: compare* (All (b c)
|
||||||
((Listof (Metric b c (Listof NumF)))
|
((Listof (Metric b c (Listof NumF)))
|
||||||
->
|
->
|
||||||
(Listof (Result (Listof NumF) b c)))))
|
(Listof (Result (Listof NumF) b c)))))
|
||||||
|
@ -480,7 +480,7 @@
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; UTILITY
|
;; UTILITY
|
||||||
|
|
||||||
(pdefine: (X Y) (imap [f : (X -> Y)] [il : (Listof X)]) : (Listof Y)
|
(pdefine: (X Y) (imap [f : (X -> Y)] [il : (Listof X)]) : (Listof Y)
|
||||||
(cond
|
(cond
|
||||||
[(null? il) '()]
|
[(null? il) '()]
|
||||||
[(not (pair? il)) (list (f il))]
|
[(not (pair? il)) (list (f il))]
|
||||||
|
@ -524,31 +524,31 @@
|
||||||
|
|
||||||
;; unused (and untypeable)
|
;; unused (and untypeable)
|
||||||
#;(define: (/* . [args : (Listof number)]) : number ;;((number)) against (number) and USELESS
|
#;(define: (/* . [args : (Listof number)]) : number ;;((number)) against (number) and USELESS
|
||||||
(apply map (lambda: ([ns : number]) (apply / ns)) args))
|
(apply map (lambda: ([ns : number]) (apply / ns)) args))
|
||||||
|
|
||||||
|
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; MAIN ENTRY POINT
|
;; MAIN ENTRY POINT
|
||||||
|
|
||||||
(define: results :
|
(define: results :
|
||||||
#;Any
|
#;Any
|
||||||
;; FIXME bug in typed scheme when this type is used
|
;; FIXME bug in typed scheme when this type is used
|
||||||
|
|
||||||
(Listof (U (Result (Listof NumF) (Listof Atom-display) (Listof Sexpr))
|
(Listof (U (Result (Listof NumF) (Listof Atom-display) (Listof Sexpr))
|
||||||
(Result (Listof NumF) (Listof Atom-display) Sexpr)))
|
(Result (Listof NumF) (Listof Atom-display) Sexpr)))
|
||||||
'())
|
'())
|
||||||
; just in case i want to do some more analysis on the results afterwards,
|
; just in case i want to do some more analysis on the results afterwards,
|
||||||
; so i don't have to waste a minute if i forget to bind the return value to something
|
; so i don't have to waste a minute if i forget to bind the return value to something
|
||||||
(define: (run-all-tests) : top
|
(define: (run-all-tests) : top
|
||||||
(let*: ([rs1 : (Listof (Result (Listof NumF) (Listof Atom-display) (Listof Any)))
|
(let*: ([rs1 : (Listof (Result (Listof NumF) (Listof Atom-display) (Listof Any)))
|
||||||
(#{compare* @ (Listof Atom-display) (Listof Any)}
|
(#{compare* @ (Listof Atom-display) (Listof Any)}
|
||||||
(list module-metrics))]
|
(list module-metrics))]
|
||||||
[rs2 : (Listof (Result (Listof NumF) (Listof Atom-display) Any))
|
[rs2 : (Listof (Result (Listof NumF) (Listof Atom-display) Any))
|
||||||
(#{compare* @ (Listof Atom-display) Any}
|
(#{compare* @ (Listof Atom-display) Any}
|
||||||
(list tl-expr-metrics))])
|
(list tl-expr-metrics))])
|
||||||
(let
|
(let
|
||||||
([rs (append rs1 rs2)])
|
([rs (append rs1 rs2)])
|
||||||
(set! results rs)
|
(set! results rs)
|
||||||
(for-each #{pretty-print-result @ (Listof Any)} rs1)
|
(for-each #{pretty-print-result @ (Listof Any)} rs1)
|
||||||
(for-each #{pretty-print-result @ Any} rs2)
|
(for-each #{pretty-print-result @ Any} rs2)
|
||||||
rs)))
|
rs)))
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
(define (f . xs) 5)
|
(define (f . xs) 5)
|
||||||
|
|
||||||
(: map-with-funcs
|
(: map-with-funcs
|
||||||
(All (A ...)
|
(All (A ...)
|
||||||
(All (B ...)
|
(All (B ...)
|
||||||
((B ... B -> A) ... A ->
|
((B ... B -> A) ... A ->
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
(provide results run-all-tests)
|
(provide results run-all-tests)
|
||||||
|
|
||||||
(require (except-in scheme/list count) scheme/math scheme/path mzlib/match
|
(require (except-in scheme/list count) scheme/math scheme/path mzlib/match
|
||||||
(prefix-in srfi13: srfi/13) scheme/file
|
(prefix-in srfi13: srfi/13) scheme/file
|
||||||
(for-syntax scheme/base))
|
(for-syntax scheme/base))
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
(define-type-alias NumF (U Number #f))
|
(define-type-alias NumF (U Number #f))
|
||||||
|
|
||||||
(define-type-alias (Unit C) ((C -> (Listof NumF)) -> (Path -> (Listof (U #f (Listof NumF))))))
|
(define-type-alias (Unit C) ((C -> (Listof NumF)) -> (Path -> (Listof (U #f (Listof NumF))))))
|
||||||
|
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; CONFIG
|
;; CONFIG
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
;; in mean cannot be explained by chance.
|
;; in mean cannot be explained by chance.
|
||||||
(define (t-test seqA seqB)
|
(define (t-test seqA seqB)
|
||||||
(manual-t-test
|
(manual-t-test
|
||||||
(avg seqA) (avg seqB)
|
(avg seqA) (avg seqB)
|
||||||
(variance seqA) (variance seqB)
|
(variance seqA) (variance seqB)
|
||||||
(length seqA) (length seqB)))
|
(length seqA) (length seqB)))
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@
|
||||||
(,a-misses ,b-misses))]
|
(,a-misses ,b-misses))]
|
||||||
[expected (λ: ([i : Integer] [j : Integer])
|
[expected (λ: ([i : Integer] [j : Integer])
|
||||||
(/ (* (row-total i table) (col-total j table)) total-subjects))])
|
(/ (* (row-total i table) (col-total j table)) total-subjects))])
|
||||||
(exact->inexact
|
(exact->inexact
|
||||||
(table-sum
|
(table-sum
|
||||||
(λ (i j) (/ (sqr (- (expected i j) (table-ref i j table))) (expected i j)))
|
(λ (i j) (/ (sqr (- (expected i j) (table-ref i j table))) (expected i j)))
|
||||||
table)))))
|
table)))))
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
;; UNITS OF MEASUREMENT IMPLEMENTATIONS
|
;; UNITS OF MEASUREMENT IMPLEMENTATIONS
|
||||||
|
|
||||||
(: per-module (All (X) (((Listof Any) -> X) -> (Path -> (List (U #f X))))))
|
(: per-module (All (X) (((Listof Any) -> X) -> (Path -> (List (U #f X))))))
|
||||||
(define (per-module f)
|
(define (per-module f)
|
||||||
(λ (path)
|
(λ (path)
|
||||||
(with-handlers ([exn:fail:read? (λ (e) (list #f))])
|
(with-handlers ([exn:fail:read? (λ (e) (list #f))])
|
||||||
(let ([initial-sexp (with-input-from-file path read)])
|
(let ([initial-sexp (with-input-from-file path read)])
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
|
|
||||||
(: per-module-top-level-expression ((Any -> (Listof NumF)) -> MetricFn))
|
(: per-module-top-level-expression ((Any -> (Listof NumF)) -> MetricFn))
|
||||||
(define (per-module-top-level-expression f)
|
(define (per-module-top-level-expression f)
|
||||||
(let ([calc (per-module (λ: ([exprs : (Listof Any)]) (map f exprs)))])
|
(let ([calc (per-module (λ: ([exprs : (Listof Any)]) (map f exprs)))])
|
||||||
(λ (p) (let ([r (calc p)]) (if (car r) (car r) r)))))
|
(λ (p) (let ([r (calc p)]) (if (car r) (car r) r)))))
|
||||||
|
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
|
@ -149,10 +149,10 @@
|
||||||
(* (/ set!s atoms) 1000.0))))
|
(* (/ set!s atoms) 1000.0))))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; contracts
|
;; contracts
|
||||||
|
|
||||||
(: uses-contracts ((Listof Any) -> Boolean))
|
(: uses-contracts ((Listof Any) -> Boolean))
|
||||||
(define (uses-contracts exprs)
|
(define (uses-contracts exprs)
|
||||||
(ormap (λ (e)
|
(ormap (λ (e)
|
||||||
(ann
|
(ann
|
||||||
(match e
|
(match e
|
||||||
|
@ -173,12 +173,12 @@
|
||||||
exprs))
|
exprs))
|
||||||
|
|
||||||
(: uncontracted-provides ((Listof Any) -> Number))
|
(: uncontracted-provides ((Listof Any) -> Number))
|
||||||
(define (uncontracted-provides exprs)
|
(define (uncontracted-provides exprs)
|
||||||
(foldl
|
(foldl
|
||||||
(λ: ([t : Any] [r : Number])
|
(λ: ([t : Any] [r : Number])
|
||||||
(ann
|
(ann
|
||||||
(match t
|
(match t
|
||||||
[`(provide ,p ...) (+ (length p) r)]
|
[`(provide ,p ...) (+ (length p) r)]
|
||||||
[_ r]) : Number))
|
[_ r]) : Number))
|
||||||
0
|
0
|
||||||
exprs))
|
exprs))
|
||||||
|
@ -237,7 +237,7 @@
|
||||||
(define-type-alias Table (Listof (Listof Number)))
|
(define-type-alias Table (Listof (Listof Number)))
|
||||||
(define-type-alias Atom-display (cons Symbol (Listof Number)))
|
(define-type-alias Atom-display (cons Symbol (Listof Number)))
|
||||||
|
|
||||||
(: standard-display (Symbol ((Listof Number) -> Number) ((Listof Number) (Listof Number) -> Number)
|
(: standard-display (Symbol ((Listof Number) -> Number) ((Listof Number) (Listof Number) -> Number)
|
||||||
-> ((Listof NumF) (Listof NumF) -> Atom-display)))
|
-> ((Listof NumF) (Listof NumF) -> Atom-display)))
|
||||||
(define ((standard-display name summarize significance-test) seqA seqB)
|
(define ((standard-display name summarize significance-test) seqA seqB)
|
||||||
(let ([clean-seqA (nonfalses seqA)]
|
(let ([clean-seqA (nonfalses seqA)]
|
||||||
|
@ -252,28 +252,28 @@
|
||||||
|
|
||||||
(: combine-metrics (All (c) ((Listof (metric Atom-display c NumF)) -> (metric (Listof Atom-display) c (Listof NumF)))))
|
(: combine-metrics (All (c) ((Listof (metric Atom-display c NumF)) -> (metric (Listof Atom-display) c (Listof NumF)))))
|
||||||
(define (combine-metrics ms)
|
(define (combine-metrics ms)
|
||||||
(let ([u (metric-analysis-unit (car ms))])
|
(let ([u (metric-analysis-unit (car ms))])
|
||||||
;; This test now redundant b/c of typechecking
|
;; This test now redundant b/c of typechecking
|
||||||
(unless (andmap (λ: ([m : (metric Atom-display c NumF) ]) (eq? u (metric-analysis-unit m))) ms)
|
(unless (andmap (λ: ([m : (metric Atom-display c NumF) ]) (eq? u (metric-analysis-unit m))) ms)
|
||||||
(error 'combine-metrics "all combined metrics must operate on the same unit of analysis"))
|
(error 'combine-metrics "all combined metrics must operate on the same unit of analysis"))
|
||||||
|
|
||||||
(make-metric
|
(make-metric
|
||||||
u
|
u
|
||||||
(λ: ([exprs : c]) (map (λ: ([m : (metric Atom-display c NumF)]) ((metric-computation m) exprs)) ms))
|
(λ: ([exprs : c]) (map (λ: ([m : (metric Atom-display c NumF)]) ((metric-computation m) exprs)) ms))
|
||||||
(λ: ([seqA : (Listof (Listof NumF))] [seqB : (Listof (Listof NumF))])
|
(λ: ([seqA : (Listof (Listof NumF))] [seqB : (Listof (Listof NumF))])
|
||||||
(map (λ: ([m : (metric Atom-display c NumF)]
|
(map (λ: ([m : (metric Atom-display c NumF)]
|
||||||
[sA : (Listof NumF)]
|
[sA : (Listof NumF)]
|
||||||
[sB : (Listof NumF)])
|
[sB : (Listof NumF)])
|
||||||
((metric->display m) sA sB)) ms (pivot seqA) (pivot seqB))))))
|
((metric->display m) sA sB)) ms (pivot seqA) (pivot seqB))))))
|
||||||
|
|
||||||
;; FIXME - (filter (lambda (x) x) l)
|
;; FIXME - (filter (lambda (x) x) l)
|
||||||
(: nonfalses (All (X) ((Listof (U #f X)) -> (Listof X))))
|
(: nonfalses (All (X) ((Listof (U #f X)) -> (Listof X))))
|
||||||
(define (nonfalses l)
|
(define (nonfalses l)
|
||||||
(let loop ([lst l])
|
(let loop ([lst l])
|
||||||
(if (null? lst)
|
(if (null? lst)
|
||||||
'()
|
'()
|
||||||
(let ([x (car lst)])
|
(let ([x (car lst)])
|
||||||
(if x
|
(if x
|
||||||
(cons x (loop (cdr lst)))
|
(cons x (loop (cdr lst)))
|
||||||
(loop (cdr lst)))))))
|
(loop (cdr lst)))))))
|
||||||
|
|
||||||
|
@ -290,22 +290,22 @@
|
||||||
(define name (kind u 'name fn )) ...
|
(define name (kind u 'name fn )) ...
|
||||||
(define all-metrics-id (combine-metrics (list name ...))))]))
|
(define all-metrics-id (combine-metrics (list name ...))))]))
|
||||||
|
|
||||||
(define-metrics module-metrics #{per-module @ (Listof NumF)}
|
(define-metrics module-metrics #{per-module @ (Listof NumF)}
|
||||||
(maximum-sexp-depth interval max-sexp-depth)
|
(maximum-sexp-depth interval max-sexp-depth)
|
||||||
(average-sexp-depth interval avg-sexp-depth)
|
(average-sexp-depth interval avg-sexp-depth)
|
||||||
(number-of-setbangs/mod interval count-setbangs/ilist)
|
(number-of-setbangs/mod interval count-setbangs/ilist)
|
||||||
(number-of-exprs interval #{length @ Any})
|
(number-of-exprs interval #{length @ Any})
|
||||||
(uses-setbang?/mod count module-has-setbangs?)
|
(uses-setbang?/mod count module-has-setbangs?)
|
||||||
(uses-contracts? count uses-contracts)
|
(uses-contracts? count uses-contracts)
|
||||||
(number-of-contracts interval contracted-provides)
|
(number-of-contracts interval contracted-provides)
|
||||||
(num-uncontracted-provides interval uncontracted-provides)
|
(num-uncontracted-provides interval uncontracted-provides)
|
||||||
(number-of-macro-defs interval num-of-define-syntax)
|
(number-of-macro-defs interval num-of-define-syntax)
|
||||||
(maximum-num-atoms interval max-atoms)
|
(maximum-num-atoms interval max-atoms)
|
||||||
(average-num-atoms interval avg-atoms)
|
(average-num-atoms interval avg-atoms)
|
||||||
(total-num-atoms/mod interval total-atoms)
|
(total-num-atoms/mod interval total-atoms)
|
||||||
(set!s-per-1000-atoms interval setbangs-per-1000-atoms))
|
(set!s-per-1000-atoms interval setbangs-per-1000-atoms))
|
||||||
|
|
||||||
(define-metrics tl-expr-metrics per-module-top-level-expression
|
(define-metrics tl-expr-metrics per-module-top-level-expression
|
||||||
(uses-setbang?/fn count expr-uses-setbangs?)
|
(uses-setbang?/fn count expr-uses-setbangs?)
|
||||||
(number-of-setbangs/fn interval count-setbangs/expr)
|
(number-of-setbangs/fn interval count-setbangs/expr)
|
||||||
(total-num-atoms/fn interval atoms))
|
(total-num-atoms/fn interval atoms))
|
||||||
|
@ -318,25 +318,25 @@
|
||||||
;; EXPERIMENT RUNNING
|
;; EXPERIMENT RUNNING
|
||||||
|
|
||||||
(define-syntax (define-excluder stx)
|
(define-syntax (define-excluder stx)
|
||||||
|
|
||||||
(define (path->clause c)
|
(define (path->clause c)
|
||||||
(syntax-case c ()
|
(syntax-case c ()
|
||||||
[(item ...)
|
[(item ...)
|
||||||
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
#`[`(#,@(reverse (syntax-e #'(item ...))) ,_ (... ...)) #t]]
|
||||||
[item
|
[item
|
||||||
#`[`(item) #t]]))
|
#`[`(item) #t]]))
|
||||||
|
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ name path ...)
|
[(_ name path ...)
|
||||||
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
(with-syntax ([(match-clause ...) (map path->clause (syntax-e #'(path ...)))])
|
||||||
#`(define (name p )
|
#`(define (name p )
|
||||||
(let* ([dirnames (map path->string (filter path? (explode-path p)))])
|
(let* ([dirnames (map path->string (filter path? (explode-path p)))])
|
||||||
(match (reverse dirnames) ; goofy backwards matching because ... matches greedily
|
(match (reverse dirnames) ; goofy backwards matching because ... matches greedily
|
||||||
match-clause ...
|
match-clause ...
|
||||||
[_ #f]))))]))
|
[_ #f]))))]))
|
||||||
|
|
||||||
(: default-excluder (Path -> Boolean))
|
(: default-excluder (Path -> Boolean))
|
||||||
(define-excluder default-excluder
|
(define-excluder default-excluder
|
||||||
"compiled" ".svn" #;("collects" "drscheme") #;("collects" "framework"))
|
"compiled" ".svn" #;("collects" "drscheme") #;("collects" "framework"))
|
||||||
|
|
||||||
(define exclude-directory? (make-parameter default-excluder))
|
(define exclude-directory? (make-parameter default-excluder))
|
||||||
|
@ -357,17 +357,17 @@
|
||||||
[(regexp-match #rx"(ss|scm)$" extension)
|
[(regexp-match #rx"(ss|scm)$" extension)
|
||||||
(let ([resl (f path)])
|
(let ([resl (f path)])
|
||||||
(if resl
|
(if resl
|
||||||
(values (cons resl acc) #t)
|
(values (cons resl acc) #t)
|
||||||
(values acc #t)))]
|
(values acc #t)))]
|
||||||
[else (values acc #t)]))]
|
[else (values acc #t)]))]
|
||||||
[(dir)
|
[(dir)
|
||||||
(let* ([p (normalize-path path root)])
|
(let* ([p (normalize-path path root)])
|
||||||
(if ((exclude-directory?) p)
|
(if ((exclude-directory?) p)
|
||||||
(values acc #f)
|
(values acc #f)
|
||||||
(values acc #t)))]
|
(values acc #t)))]
|
||||||
[(link) (values acc #t)]))
|
[(link) (values acc #t)]))
|
||||||
'()
|
'()
|
||||||
root))
|
root))
|
||||||
(define-typed-struct (a b c) result ([metric : (metric b c a)] [seqA : (Listof a)] [seqB : (Listof a)]))
|
(define-typed-struct (a b c) result ([metric : (metric b c a)] [seqA : (Listof a)] [seqB : (Listof a)]))
|
||||||
(define-type-alias MetricFn (Path -> (Listof (U #f (Listof NumF)))))
|
(define-type-alias MetricFn (Path -> (Listof (U #f (Listof NumF)))))
|
||||||
|
|
||||||
|
@ -380,16 +380,16 @@
|
||||||
(: selector (case-lambda [(M b c) -> MetricFn] [(M b C) -> MetricFn]))
|
(: selector (case-lambda [(M b c) -> MetricFn] [(M b C) -> MetricFn]))
|
||||||
(define (selector m) ((metric-analysis-unit m) (metric-computation m)))
|
(define (selector m) ((metric-analysis-unit m) (metric-computation m)))
|
||||||
(let* ([metric-fns (map #{selector :: ((M2 b c C) -> MetricFn)} metrics)]
|
(let* ([metric-fns (map #{selector :: ((M2 b c C) -> MetricFn)} metrics)]
|
||||||
[result-seqs (apply-to-scheme-files
|
[result-seqs (apply-to-scheme-files
|
||||||
(λ: ([file : Path])
|
(λ: ([file : Path])
|
||||||
(map (λ: ([fn : MetricFn]) (fn file)) metric-fns)) path)])
|
(map (λ: ([fn : MetricFn]) (fn file)) metric-fns)) path)])
|
||||||
(map
|
(map
|
||||||
(λ: ([l : (Listof (Listof (U #f (Listof NumF))))])
|
(λ: ([l : (Listof (Listof (U #f (Listof NumF))))])
|
||||||
(nonfalses (apply append l)))
|
(nonfalses (apply append l)))
|
||||||
(pivot (nonfalses result-seqs)))))
|
(pivot (nonfalses result-seqs)))))
|
||||||
|
|
||||||
|
|
||||||
(: compare*
|
|
||||||
|
(: compare*
|
||||||
(All (b c c*)
|
(All (b c c*)
|
||||||
((List (M b c) (M b c*))
|
((List (M b c) (M b c*))
|
||||||
->
|
->
|
||||||
|
@ -408,7 +408,7 @@
|
||||||
(result-seqA result)
|
(result-seqA result)
|
||||||
(result-seqB result)))
|
(result-seqB result)))
|
||||||
|
|
||||||
(: pretty-print-result
|
(: pretty-print-result
|
||||||
(case-lambda
|
(case-lambda
|
||||||
((result (Listof NumF) (Listof Atom-display) (Listof Any)) -> Void)
|
((result (Listof NumF) (Listof Atom-display) (Listof Any)) -> Void)
|
||||||
((result (Listof NumF) (Listof Atom-display) Any) -> Void)))
|
((result (Listof NumF) (Listof Atom-display) Any) -> Void)))
|
||||||
|
@ -435,7 +435,7 @@
|
||||||
;; UTILITY
|
;; UTILITY
|
||||||
|
|
||||||
(: imap (All (Y) ((Any -> Y) Any -> (Listof Y))))
|
(: imap (All (Y) ((Any -> Y) Any -> (Listof Y))))
|
||||||
(define (imap f il)
|
(define (imap f il)
|
||||||
(cond
|
(cond
|
||||||
[(null? il) '()]
|
[(null? il) '()]
|
||||||
[(not (pair? il)) (list (f il))]
|
[(not (pair? il)) (list (f il))]
|
||||||
|
@ -491,16 +491,16 @@
|
||||||
;; ============================================================
|
;; ============================================================
|
||||||
;; MAIN ENTRY POINT
|
;; MAIN ENTRY POINT
|
||||||
|
|
||||||
(: results (U #f (Listof (U (result (Listof NumF) (Listof Atom-display) (Listof Any))
|
(: results (U #f (Listof (U (result (Listof NumF) (Listof Atom-display) (Listof Any))
|
||||||
(result (Listof NumF) (Listof Atom-display) Any)))))
|
(result (Listof NumF) (Listof Atom-display) Any)))))
|
||||||
(define results #f) ; just in case i want to do some more analysis on the results afterwards,
|
(define results #f) ; just in case i want to do some more analysis on the results afterwards,
|
||||||
; so i don't have to waste a minute if i forget to bind the return value to something
|
; so i don't have to waste a minute if i forget to bind the return value to something
|
||||||
|
|
||||||
(define (run-all-tests)
|
(define (run-all-tests)
|
||||||
(let ([rs (compare* all-metrics)])
|
(let ([rs (compare* all-metrics)])
|
||||||
(set! results rs)
|
(set! results rs)
|
||||||
(for-each
|
(for-each
|
||||||
(ann pretty-print-result ((U (result (Listof NumF) (Listof Atom-display) (Listof Any))
|
(ann pretty-print-result ((U (result (Listof NumF) (Listof Atom-display) (Listof Any))
|
||||||
(result (Listof NumF) (Listof Atom-display) Any))
|
(result (Listof NumF) (Listof Atom-display) Any))
|
||||||
-> Any))
|
-> Any))
|
||||||
rs)
|
rs)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#;#;
|
#;#;
|
||||||
(: g (Any -> Boolean : (U 'r 's)))
|
(: g (Any -> Boolean : (U 'r 's)))
|
||||||
(define (g x)
|
(define (g x)
|
||||||
(let ([q x])
|
(let ([q x])
|
||||||
(let ([op2 (eq? 'r x)])
|
(let ([op2 (eq? 'r x)])
|
||||||
(if op2 op2 (eq? 's x)))))
|
(if op2 op2 (eq? 's x)))))
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
(let ([op1 (eq? 'q x)])
|
(let ([op1 (eq? 'q x)])
|
||||||
(if op1 op1
|
(if op1 op1
|
||||||
(let ([op2 (eq? 'r x)])
|
(let ([op2 (eq? 'r x)])
|
||||||
(if op2
|
(if op2
|
||||||
;; !#f_op2
|
;; !#f_op2
|
||||||
op2
|
op2
|
||||||
(eq? 's x)))))))
|
(eq? 's x)))))))
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
(: other-foo-path Path-For-Some-System)
|
(: other-foo-path Path-For-Some-System)
|
||||||
(define other-foo-path
|
(define other-foo-path
|
||||||
(build-path/convention-type other-system
|
(build-path/convention-type other-system
|
||||||
(string->some-system-path "foo" other-system)
|
(string->some-system-path "foo" other-system)
|
||||||
(string->some-system-path "bar" other-system)
|
(string->some-system-path "bar" other-system)
|
||||||
'same
|
'same
|
||||||
'up))
|
'up))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(: no-exec (-> Void))
|
(: no-exec (-> Void))
|
||||||
(define (no-exec)
|
(define (no-exec)
|
||||||
|
|
||||||
|
|
||||||
(call-with-output-file "file.tmp"
|
(call-with-output-file "file.tmp"
|
||||||
(lambda: ((port : Output-Port))
|
(lambda: ((port : Output-Port))
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
(make-directory "tmp-dir")
|
(make-directory "tmp-dir")
|
||||||
|
|
||||||
(path-only "file.tmp")
|
(path-only "file.tmp")
|
||||||
|
|
||||||
(system #"echo foo")
|
(system #"echo foo")
|
||||||
(system* "/bin/echo" "zzz" #"foo" (string->path "/"))
|
(system* "/bin/echo" "zzz" #"foo" (string->path "/"))
|
||||||
(system/exit-code #"echo foo")
|
(system/exit-code #"echo foo")
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
[else (cons (f (car l))
|
[else (cons (f (car l))
|
||||||
(mymap2 f (cdr l)))]))
|
(mymap2 f (cdr l)))]))
|
||||||
|
|
||||||
(define: x : (list-of number)
|
(define: x : (list-of number)
|
||||||
(mymap (lambda: ([x : number]) (+ 3 x)) (cons 1 (cons 4 #{'() : (list-of number)}))))
|
(mymap (lambda: ([x : number]) (+ 3 x)) (cons 1 (cons 4 #{'() : (list-of number)}))))
|
||||||
|
|
||||||
(define: x2 : (list-of number)
|
(define: x2 : (list-of number)
|
||||||
(mymap2 (lambda: ([x : number]) (+ 3 x)) (cons 1 (cons 4 #{'() : (list-of number)}))))
|
(mymap2 (lambda: ([x : number]) (+ 3 x)) (cons 1 (cons 4 #{'() : (list-of number)}))))
|
||||||
|
|
||||||
(provide x2)
|
(provide x2)
|
||||||
|
|
|
@ -10,5 +10,5 @@
|
||||||
[(null? lsn) 0]
|
[(null? lsn) 0]
|
||||||
[(number? (car lsn)) (+ (car lsn) (sum (cdr lsn)))]
|
[(number? (car lsn)) (+ (car lsn) (sum (cdr lsn)))]
|
||||||
[else (sum (cdr lsn))]))
|
[else (sum (cdr lsn))]))
|
||||||
|
|
||||||
(sum '(a b 2 3))
|
(sum '(a b 2 3))
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#lang racket/load
|
#lang racket/load
|
||||||
|
|
||||||
(module T typed/racket
|
(module T typed/racket
|
||||||
|
|
||||||
(struct: [X] doll ([contents : X]))
|
(struct: [X] doll ([contents : X]))
|
||||||
|
|
||||||
(define-type RussianDoll
|
(define-type RussianDoll
|
||||||
(Rec RD (U 'center (doll RD))))
|
(Rec RD (U 'center (doll RD))))
|
||||||
|
|
||||||
(: f (RussianDoll -> RussianDoll))
|
(: f (RussianDoll -> RussianDoll))
|
||||||
(define (f rd) rd)
|
(define (f rd) rd)
|
||||||
|
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(require 'T)
|
(require 'T)
|
||||||
|
|
|
@ -10,5 +10,5 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
(module client typed-scheme
|
(module client typed-scheme
|
||||||
|
|
||||||
(require-typed-struct ast ([loc : Any]) 'source))
|
(require-typed-struct ast ([loc : Any]) 'source))
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(provide (all-defined)))
|
(provide (all-defined)))
|
||||||
|
|
||||||
(module alias typed-scheme
|
(module alias typed-scheme
|
||||||
|
|
||||||
(define-type-alias Srcloc Any)
|
(define-type-alias Srcloc Any)
|
||||||
|
|
||||||
(require-typed-struct term ([posn : Srcloc]) 'source))
|
(require-typed-struct term ([posn : Srcloc]) 'source))
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; "bug" found - handling of empty heaps
|
;; "bug" found - handling of empty heaps
|
||||||
(pdefine: (a) (find-min [pq : (priority-queue a)]) : a
|
(pdefine: (a) (find-min [pq : (priority-queue a)]) : a
|
||||||
(let ([h (heap pq)])
|
(let ([h (heap pq)])
|
||||||
(if (heap:empty? h)
|
(if (heap:empty? h)
|
||||||
(error "priority queue empty")
|
(error "priority queue empty")
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(module n2 scheme/base
|
(module n2 scheme/base
|
||||||
|
|
||||||
(require 'm scheme/match)
|
(require 'm scheme/match)
|
||||||
(match my-x
|
(match my-x
|
||||||
[(struct x (f)) (f 7)]))
|
[(struct x (f)) (f 7)]))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
|
|
||||||
(module m typed-scheme
|
(module m typed-scheme
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
; MODULE DEFINITION FOR SRFI-27
|
; MODULE DEFINITION FOR SRFI-27
|
||||||
; =============================
|
; =============================
|
||||||
;
|
;
|
||||||
; Sebastian.Egner@philips.com, Mar-2002, in PLT 204
|
; Sebastian.Egner@philips.com, Mar-2002, in PLT 204
|
||||||
;
|
;
|
||||||
; This file contains the top-level definition for the 54-bit integer-only
|
; This file contains the top-level definition for the 54-bit integer-only
|
||||||
; implementation of SRFI 27 for the PLT 204 DrScheme system.
|
; implementation of SRFI 27 for the PLT 204 DrScheme system.
|
||||||
;
|
;
|
||||||
; 1. The core generator is implemented in 'mrg32k3a-a.scm'.
|
; 1. The core generator is implemented in 'mrg32k3a-a.scm'.
|
||||||
; 2. The generic parts of the interface are in 'mrg32k3a.scm'.
|
; 2. The generic parts of the interface are in 'mrg32k3a.scm'.
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
#;(require srfi/9)
|
#;(require srfi/9)
|
||||||
#;(require srfi/23)
|
#;(require srfi/23)
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
random-integer random-real default-random-source
|
random-integer random-real default-random-source
|
||||||
make-random-source random-source? random-source-state-ref
|
make-random-source random-source? random-source-state-ref
|
||||||
random-source-state-set! random-source-randomize!
|
random-source-state-set! random-source-randomize!
|
||||||
|
@ -37,19 +37,19 @@
|
||||||
[state-set! : ((Listof Nb)-> Void)]
|
[state-set! : ((Listof Nb)-> Void)]
|
||||||
[randomize! : ( -> Void)]
|
[randomize! : ( -> Void)]
|
||||||
[pseudo-randomize! : (Integer Integer -> Void)]
|
[pseudo-randomize! : (Integer Integer -> Void)]
|
||||||
[make-integers : (-> (Integer -> Integer)) ]
|
[make-integers : (-> (Integer -> Integer)) ]
|
||||||
[make-reals : ( Nb * -> ( -> Number))]))
|
[make-reals : ( Nb * -> ( -> Number))]))
|
||||||
(define-type-alias Random :random-source)
|
(define-type-alias Random :random-source)
|
||||||
(define: (:random-source-make
|
(define: (:random-source-make
|
||||||
[state-ref : ( -> SpList)]
|
[state-ref : ( -> SpList)]
|
||||||
[state-set! : ((Listof Nb)-> Void)]
|
[state-set! : ((Listof Nb)-> Void)]
|
||||||
[randomize! : ( -> Void)]
|
[randomize! : ( -> Void)]
|
||||||
[pseudo-randomize! : (Integer Integer -> Void)]
|
[pseudo-randomize! : (Integer Integer -> Void)]
|
||||||
[make-integers : (-> (Integer -> Integer)) ]
|
[make-integers : (-> (Integer -> Integer)) ]
|
||||||
[make-reals : (Nb * -> (-> Number))])
|
[make-reals : (Nb * -> (-> Number))])
|
||||||
: Random
|
: Random
|
||||||
(make-:random-source state-ref state-set! randomize! pseudo-randomize! make-integers make-reals ))
|
(make-:random-source state-ref state-set! randomize! pseudo-randomize! make-integers make-reals ))
|
||||||
|
|
||||||
#;(define-record-type :random-source
|
#;(define-record-type :random-source
|
||||||
(:random-source-make
|
(:random-source-make
|
||||||
state-ref
|
state-ref
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
(pseudo-randomize! :random-source-pseudo-randomize!)
|
(pseudo-randomize! :random-source-pseudo-randomize!)
|
||||||
(make-integers :random-source-make-integers)
|
(make-integers :random-source-make-integers)
|
||||||
(make-reals :random-source-make-reals))
|
(make-reals :random-source-make-reals))
|
||||||
|
|
||||||
(define: :random-source-current-time : ( -> Nb )
|
(define: :random-source-current-time : ( -> Nb )
|
||||||
current-milliseconds) ;;on verra apres
|
current-milliseconds) ;;on verra apres
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
; the actual generator
|
; the actual generator
|
||||||
|
|
||||||
|
|
||||||
(define: (mrg32k3a-random-m1 [state : State]) : Nb
|
(define: (mrg32k3a-random-m1 [state : State]) : Nb
|
||||||
(let ((x11 (vector-ref state 0))
|
(let ((x11 (vector-ref state 0))
|
||||||
(x12 (vector-ref state 1))
|
(x12 (vector-ref state 1))
|
||||||
|
@ -153,8 +153,8 @@
|
||||||
; Generator
|
; Generator
|
||||||
; =========
|
; =========
|
||||||
;
|
;
|
||||||
; Pierre L'Ecuyer's MRG32k3a generator is a Combined Multiple Recursive
|
; Pierre L'Ecuyer's MRG32k3a generator is a Combined Multiple Recursive
|
||||||
; Generator. It produces the sequence {(x[1,n] - x[2,n]) mod m1 : n}
|
; Generator. It produces the sequence {(x[1,n] - x[2,n]) mod m1 : n}
|
||||||
; defined by the two recursive generators
|
; defined by the two recursive generators
|
||||||
;
|
;
|
||||||
; x[1,n] = ( a12 x[1,n-2] + a13 x[1,n-3]) mod m1,
|
; x[1,n] = ( a12 x[1,n-2] + a13 x[1,n-3]) mod m1,
|
||||||
|
@ -182,15 +182,15 @@
|
||||||
; publication provides detailed information on how to do that:
|
; publication provides detailed information on how to do that:
|
||||||
;
|
;
|
||||||
; [1] P. L'Ecuyer, R. Simard, E. J. Chen, W. D. Kelton:
|
; [1] P. L'Ecuyer, R. Simard, E. J. Chen, W. D. Kelton:
|
||||||
; An Object-Oriented Random-Number Package With Many Long
|
; An Object-Oriented Random-Number Package With Many Long
|
||||||
; Streams and Substreams. 2001.
|
; Streams and Substreams. 2001.
|
||||||
; To appear in Operations Research.
|
; To appear in Operations Research.
|
||||||
;
|
;
|
||||||
; Arithmetics
|
; Arithmetics
|
||||||
; ===========
|
; ===========
|
||||||
;
|
;
|
||||||
; The MRG32k3a generator produces values in {0..2^32-209-1}. All
|
; The MRG32k3a generator produces values in {0..2^32-209-1}. All
|
||||||
; subexpressions of the actual generator fit into {-2^53..2^53-1}.
|
; subexpressions of the actual generator fit into {-2^53..2^53-1}.
|
||||||
; The code below assumes that Scheme's "integer" covers this range.
|
; The code below assumes that Scheme's "integer" covers this range.
|
||||||
; In addition, it is assumed that floating point literals can be
|
; In addition, it is assumed that floating point literals can be
|
||||||
; read and there is some arithmetics with inexact numbers.
|
; read and there is some arithmetics with inexact numbers.
|
||||||
|
@ -210,16 +210,16 @@
|
||||||
; pack/unpack a state of the generator. The core generator works
|
; pack/unpack a state of the generator. The core generator works
|
||||||
; on packed states, passed as an explicit argument, only. This
|
; on packed states, passed as an explicit argument, only. This
|
||||||
; allows native code implementations to store their state in a
|
; allows native code implementations to store their state in a
|
||||||
; suitable form. Unpacked states are #(x10 x11 x12 x20 x21 x22)
|
; suitable form. Unpacked states are #(x10 x11 x12 x20 x21 x22)
|
||||||
; with integer x_ij. Pack/unpack need not allocate new objects
|
; with integer x_ij. Pack/unpack need not allocate new objects
|
||||||
; in case packed and unpacked states are identical.
|
; in case packed and unpacked states are identical.
|
||||||
;
|
;
|
||||||
; (mrg32k3a-random-range) -> m-max
|
; (mrg32k3a-random-range) -> m-max
|
||||||
; (mrg32k3a-random-integer packed-state range) -> x in {0..range-1}
|
; (mrg32k3a-random-integer packed-state range) -> x in {0..range-1}
|
||||||
; advance the state of the generator and return the next random
|
; advance the state of the generator and return the next random
|
||||||
; range-limited integer.
|
; range-limited integer.
|
||||||
; Note that the state is not necessarily advanced by just one
|
; Note that the state is not necessarily advanced by just one
|
||||||
; step because we use the rejection method to avoid any problems
|
; step because we use the rejection method to avoid any problems
|
||||||
; with distribution anomalies.
|
; with distribution anomalies.
|
||||||
; The range argument must be an exact integer in {1..m-max}.
|
; The range argument must be an exact integer in {1..m-max}.
|
||||||
; It can be assumed that range is a fixnum if the Scheme system
|
; It can be assumed that range is a fixnum if the Scheme system
|
||||||
|
@ -237,7 +237,7 @@
|
||||||
; to be defined to create and access a new record data type:
|
; to be defined to create and access a new record data type:
|
||||||
;
|
;
|
||||||
; (:random-source-make a0 a1 a2 a3 a4 a5) -> s
|
; (:random-source-make a0 a1 a2 a3 a4 a5) -> s
|
||||||
; constructs a new random source object s consisting of the
|
; constructs a new random source object s consisting of the
|
||||||
; objects a0 .. a5 in this order.
|
; objects a0 .. a5 in this order.
|
||||||
;
|
;
|
||||||
; (:random-source? obj) -> bool
|
; (:random-source? obj) -> bool
|
||||||
|
@ -267,7 +267,7 @@
|
||||||
; ===================
|
; ===================
|
||||||
|
|
||||||
(define: (mrg32k3a-state-ref [packed-state : State ]) : (cons 'lecuyer-mrg32k3a (Listof Nb))
|
(define: (mrg32k3a-state-ref [packed-state : State ]) : (cons 'lecuyer-mrg32k3a (Listof Nb))
|
||||||
(cons 'lecuyer-mrg32k3a
|
(cons 'lecuyer-mrg32k3a
|
||||||
(vector->list (mrg32k3a-unpack-state packed-state))))
|
(vector->list (mrg32k3a-unpack-state packed-state))))
|
||||||
|
|
||||||
(define: (mrg32k3a-state-set [external-state : (Listof Nb)]) : State
|
(define: (mrg32k3a-state-set [external-state : (Listof Nb)]) : State
|
||||||
|
@ -299,7 +299,7 @@
|
||||||
; Pseudo-Randomization
|
; Pseudo-Randomization
|
||||||
; ====================
|
; ====================
|
||||||
;
|
;
|
||||||
; Reference [1] above shows how to obtain many long streams and
|
; Reference [1] above shows how to obtain many long streams and
|
||||||
; substream from the backbone generator.
|
; substream from the backbone generator.
|
||||||
;
|
;
|
||||||
; The idea is that the generator is a linear operation on the state.
|
; The idea is that the generator is a linear operation on the state.
|
||||||
|
@ -312,7 +312,7 @@
|
||||||
; For the implementation it is necessary to compute with matrices in
|
; For the implementation it is necessary to compute with matrices in
|
||||||
; the ring (Z/(m1*m1)*Z)^(3x3). By the Chinese-Remainder Theorem, this
|
; the ring (Z/(m1*m1)*Z)^(3x3). By the Chinese-Remainder Theorem, this
|
||||||
; is isomorphic to ((Z/m1*Z) x (Z/m2*Z))^(3x3). We represent such a pair
|
; is isomorphic to ((Z/m1*Z) x (Z/m2*Z))^(3x3). We represent such a pair
|
||||||
; of matrices
|
; of matrices
|
||||||
; [ [[x00 x01 x02],
|
; [ [[x00 x01 x02],
|
||||||
; [x10 x11 x12],
|
; [x10 x11 x12],
|
||||||
; [x20 x21 x22]], mod m1
|
; [x20 x21 x22]], mod m1
|
||||||
|
@ -324,9 +324,9 @@
|
||||||
; y00 y01 y02 y10 y11 y12 y20 y21 y22)
|
; y00 y01 y02 y10 y11 y12 y20 y21 y22)
|
||||||
;
|
;
|
||||||
; As the implementation should only use the range {-2^53..2^53-1}, the
|
; As the implementation should only use the range {-2^53..2^53-1}, the
|
||||||
; fundamental operation (x*y) mod m, where x, y, m are nearly 2^32,
|
; fundamental operation (x*y) mod m, where x, y, m are nearly 2^32,
|
||||||
; is computed by breaking up x and y as x = x1*w + x0 and y = y1*w + y0
|
; is computed by breaking up x and y as x = x1*w + x0 and y = y1*w + y0
|
||||||
; where w = 2^16. In this case, all operations fit the range because
|
; where w = 2^16. In this case, all operations fit the range because
|
||||||
; w^2 mod m is a small number. If proper multiprecision integers are
|
; w^2 mod m is a small number. If proper multiprecision integers are
|
||||||
; available this is not necessary, but pseudo-randomize! is an expected
|
; available this is not necessary, but pseudo-randomize! is an expected
|
||||||
; to be called only occasionally so we do not provide this implementation.
|
; to be called only occasionally so we do not provide this implementation.
|
||||||
|
@ -336,10 +336,10 @@
|
||||||
|
|
||||||
(define: mrg32k3a-initial-state : (Vectorof Nb); 0 3 6 9 12 15 of A^16, see below
|
(define: mrg32k3a-initial-state : (Vectorof Nb); 0 3 6 9 12 15 of A^16, see below
|
||||||
'#( 1062452522
|
'#( 1062452522
|
||||||
2961816100
|
2961816100
|
||||||
342112271
|
342112271
|
||||||
2854655037
|
2854655037
|
||||||
3321940838
|
3321940838
|
||||||
3542344109))
|
3542344109))
|
||||||
|
|
||||||
(define: mrg32k3a-generators : (Listof State) '(#(0 0 0 0 0)) ) ; computed when needed -> Changer #f by a State to hava right type.
|
(define: mrg32k3a-generators : (Listof State) '(#(0 0 0 0 0)) ) ; computed when needed -> Changer #f by a State to hava right type.
|
||||||
|
@ -365,22 +365,22 @@
|
||||||
(b2h (quotient (vector-ref B j2) w))
|
(b2h (quotient (vector-ref B j2) w))
|
||||||
(b2l (modulo (vector-ref B j2) w)))
|
(b2l (modulo (vector-ref B j2) w)))
|
||||||
(modulo
|
(modulo
|
||||||
(+ (* (+ (* a0h b0h)
|
(+ (* (+ (* a0h b0h)
|
||||||
(* a1h b1h)
|
(* a1h b1h)
|
||||||
(* a2h b2h))
|
(* a2h b2h))
|
||||||
w-sqr)
|
w-sqr)
|
||||||
(* (+ (* a0h b0l)
|
(* (+ (* a0h b0l)
|
||||||
(* a0l b0h)
|
(* a0l b0h)
|
||||||
(* a1h b1l)
|
(* a1h b1l)
|
||||||
(* a1l b1h)
|
(* a1l b1h)
|
||||||
(* a2h b2l)
|
(* a2h b2l)
|
||||||
(* a2l b2h))
|
(* a2l b2h))
|
||||||
w)
|
w)
|
||||||
(* a0l b0l)
|
(* a0l b0l)
|
||||||
(* a1l b1l)
|
(* a1l b1l)
|
||||||
(* a2l b2l))
|
(* a2l b2l))
|
||||||
m)))
|
m)))
|
||||||
|
|
||||||
(vector
|
(vector
|
||||||
(lc 0 1 2 0 3 6 mrg32k3a-m1 w-sqr1) ; (A*B)_00 mod m1
|
(lc 0 1 2 0 3 6 mrg32k3a-m1 w-sqr1) ; (A*B)_00 mod m1
|
||||||
(lc 0 1 2 1 4 7 mrg32k3a-m1 w-sqr1) ; (A*B)_01
|
(lc 0 1 2 1 4 7 mrg32k3a-m1 w-sqr1) ; (A*B)_01
|
||||||
|
@ -426,7 +426,7 @@
|
||||||
0 1 0))
|
0 1 0))
|
||||||
|
|
||||||
; check arguments
|
; check arguments
|
||||||
(when (not (and (integer? i)
|
(when (not (and (integer? i)
|
||||||
(exact? i)
|
(exact? i)
|
||||||
(integer? j)
|
(integer? j)
|
||||||
(exact? j)))
|
(exact? j)))
|
||||||
|
@ -441,12 +441,12 @@
|
||||||
(power A 16))))
|
(power A 16))))
|
||||||
|
|
||||||
; compute M = A^(16 + i*2^127 + j*2^76)
|
; compute M = A^(16 + i*2^127 + j*2^76)
|
||||||
(let ((M (product
|
(let ((M (product
|
||||||
(list-ref mrg32k3a-generators 2)
|
(list-ref mrg32k3a-generators 2)
|
||||||
(product
|
(product
|
||||||
(power (list-ref mrg32k3a-generators 0)
|
(power (list-ref mrg32k3a-generators 0)
|
||||||
(modulo i (expt 2 28)))
|
(modulo i (expt 2 28)))
|
||||||
(power (list-ref mrg32k3a-generators 1)
|
(power (list-ref mrg32k3a-generators 1)
|
||||||
(modulo j (expt 2 28)))))))
|
(modulo j (expt 2 28)))))))
|
||||||
(mrg32k3a-pack-state
|
(mrg32k3a-pack-state
|
||||||
(vector
|
(vector
|
||||||
|
@ -494,8 +494,8 @@
|
||||||
; Large Integers
|
; Large Integers
|
||||||
; ==============
|
; ==============
|
||||||
;
|
;
|
||||||
; To produce large integer random deviates, for n > m-max, we first
|
; To produce large integer random deviates, for n > m-max, we first
|
||||||
; construct large random numbers in the range {0..m-max^k-1} for some
|
; construct large random numbers in the range {0..m-max^k-1} for some
|
||||||
; k such that m-max^k >= n and then use the rejection method to choose
|
; k such that m-max^k >= n and then use the rejection method to choose
|
||||||
; uniformly from the range {0..n-1}.
|
; uniformly from the range {0..n-1}.
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@
|
||||||
(mrg32k3a-random-integer state mrg32k3a-m-max))))
|
(mrg32k3a-random-integer state mrg32k3a-m-max))))
|
||||||
|
|
||||||
(define: (mrg32k3a-random-large [state : State] [n : Nb]) : Nb ; n > m-max
|
(define: (mrg32k3a-random-large [state : State] [n : Nb]) : Nb ; n > m-max
|
||||||
(do: : Integer ((k : Integer 2 (+ k 1))
|
(do: : Integer ((k : Integer 2 (+ k 1))
|
||||||
(mk : Integer (* mrg32k3a-m-max mrg32k3a-m-max) (* mk mrg32k3a-m-max)))
|
(mk : Integer (* mrg32k3a-m-max mrg32k3a-m-max) (* mk mrg32k3a-m-max)))
|
||||||
((>= mk n)
|
((>= mk n)
|
||||||
(let* ((mk-by-n (quotient mk n))
|
(let* ((mk-by-n (quotient mk n))
|
||||||
|
@ -559,31 +559,31 @@
|
||||||
(lambda: ([n : Nb])
|
(lambda: ([n : Nb])
|
||||||
(cond
|
(cond
|
||||||
((not (and (integer? n) (exact? n) (positive? n)))
|
((not (and (integer? n) (exact? n) (positive? n)))
|
||||||
(error "range must be exact positive integer" n))
|
(error "range must be exact positive integer" n))
|
||||||
((<= n mrg32k3a-m-max)
|
((<= n mrg32k3a-m-max)
|
||||||
(mrg32k3a-random-integer state n))
|
(mrg32k3a-random-integer state n))
|
||||||
(else
|
(else
|
||||||
(mrg32k3a-random-large state n)))))
|
(mrg32k3a-random-large state n)))))
|
||||||
(lambda: [args : Nb *]
|
(lambda: [args : Nb *]
|
||||||
(cond
|
(cond
|
||||||
((null? args)
|
((null? args)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(mrg32k3a-random-real state)))
|
(mrg32k3a-random-real state)))
|
||||||
((null? (cdr args))
|
((null? (cdr args))
|
||||||
(let: ((unit : Flt (car args)))
|
(let: ((unit : Flt (car args)))
|
||||||
(cond
|
(cond
|
||||||
((not (and (real? unit) (< 0 unit 1)))
|
((not (and (real? unit) (< 0 unit 1)))
|
||||||
(error "unit must be real in (0,1)" unit))
|
(error "unit must be real in (0,1)" unit))
|
||||||
((<= (- (/ 1 unit) 1) mrg32k3a-m1)
|
((<= (- (/ 1 unit) 1) mrg32k3a-m1)
|
||||||
(lambda: ()
|
(lambda: ()
|
||||||
(mrg32k3a-random-real state)))
|
(mrg32k3a-random-real state)))
|
||||||
(else
|
(else
|
||||||
(lambda: ()
|
(lambda: ()
|
||||||
(mrg32k3a-random-real-mp state unit))))))
|
(mrg32k3a-random-real-mp state unit))))))
|
||||||
(else
|
(else
|
||||||
(error "illegal arguments" args)))))))
|
(error "illegal arguments" args)))))))
|
||||||
|
|
||||||
(define: random-source? : (Any -> Boolean : Random)
|
(define: random-source? : (Any -> Boolean : Random)
|
||||||
:random-source?)
|
:random-source?)
|
||||||
|
|
||||||
(define: (random-source-state-ref [s : Random]) : SpList
|
(define: (random-source-state-ref [s : Random]) : SpList
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
(define-typed-struct (a) heap ([compare : comparator]))
|
(define-typed-struct (a) heap ([compare : comparator]))
|
||||||
(define-typed-struct (a) (heap-empty heap) ())
|
(define-typed-struct (a) (heap-empty heap) ())
|
||||||
(define-typed-struct (a) (heap-node heap)
|
(define-typed-struct (a) (heap-node heap)
|
||||||
([rank : number] [elm : a] [left : (Un (heap-node a) (heap-empty a))] [right : (Un (heap-node a) (heap-empty a))]))
|
([rank : number] [elm : a] [left : (Un (heap-node a) (heap-empty a))] [right : (Un (heap-node a) (heap-empty a))]))
|
||||||
|
|
||||||
(define-type-alias (Heap a) (Un (heap-empty a) (heap-node a)))
|
(define-type-alias (Heap a) (Un (heap-empty a) (heap-node a)))
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
(pdefine: (b) (heap-size [h : (Heap b)]) : number
|
(pdefine: (b) (heap-size [h : (Heap b)]) : number
|
||||||
(cond [(heap-empty? h) 0]
|
(cond [(heap-empty? h) 0]
|
||||||
[(heap-node? h)
|
[(heap-node? h)
|
||||||
(+ 1 (+ (heap-size (heap-node-left h))
|
(+ 1 (+ (heap-size (heap-node-left h))
|
||||||
(heap-size (heap-node-right h))))]
|
(heap-size (heap-node-right h))))]
|
||||||
;; FIXME - shouldn't need else clause
|
;; FIXME - shouldn't need else clause
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
(define-typed-struct npheap ([compare : comparator]))
|
(define-typed-struct npheap ([compare : comparator]))
|
||||||
(define-typed-struct (npheap-empty npheap) ())
|
(define-typed-struct (npheap-empty npheap) ())
|
||||||
(define-typed-struct (npheap-node npheap)
|
(define-typed-struct (npheap-node npheap)
|
||||||
([rank : number] [elm : symbol] [left : (Un npheap-node npheap-empty)] [right : (Un npheap-node npheap-empty)]))
|
([rank : number] [elm : symbol] [left : (Un npheap-node npheap-empty)] [right : (Un npheap-node npheap-empty)]))
|
||||||
|
|
||||||
(define-type-alias npHeap (Un npheap-empty npheap-node))
|
(define-type-alias npHeap (Un npheap-empty npheap-node))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
#;(require mzlib/etc)
|
#;(require mzlib/etc)
|
||||||
#;(require "prims.ss")
|
#;(require "prims.ss")
|
||||||
(require mzlib/match)
|
(require mzlib/match)
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
(pick 2 (cons 'a (cons 'd (cons 'c #{'() : (list-of symbol)}))))
|
(pick 2 (cons 'a (cons 'd (cons 'c #{'() : (list-of symbol)}))))
|
||||||
|
|
||||||
(define: (multirember [a : atom] [l : lat]) : lat
|
(define: (multirember [a : atom] [l : lat]) : lat
|
||||||
(letrec ([#{mr : (lat -> lat)}
|
(letrec ([#{mr : (lat -> lat)}
|
||||||
(lambda: ([l : lat])
|
(lambda: ([l : lat])
|
||||||
(cond [(null? l) l]
|
(cond [(null? l) l]
|
||||||
[(eq? a (car l)) (mr (cdr l))]
|
[(eq? a (car l)) (mr (cdr l))]
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
(cond [(null? l) l]
|
(cond [(null? l) l]
|
||||||
[(f a (car l)) (mr (cdr l))]
|
[(f a (car l)) (mr (cdr l))]
|
||||||
[else (cons (car l) (mr (cdr l)))]))
|
[else (cons (car l) (mr (cdr l)))]))
|
||||||
#;(letrec ([#{mr : ((list-of e) -> (list-of e))}
|
#;(letrec ([#{mr : ((list-of e) -> (list-of e))}
|
||||||
(lambda: ([l : (list-of e)])
|
(lambda: ([l : (list-of e)])
|
||||||
(cond [(null? l) l]
|
(cond [(null? l) l]
|
||||||
[(f a (car l)) (mr (cdr l))]
|
[(f a (car l)) (mr (cdr l))]
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
(let ([tmp (number? x)]) (if tmp tmp (string? x)))
|
(let ([tmp (number? x)]) (if tmp tmp (string? x)))
|
||||||
|
|
||||||
(if (let ([tmp (number? x)])
|
(if (let ([tmp (number? x)])
|
||||||
(if tmp tmp (string? x)))
|
(if tmp tmp (string? x)))
|
||||||
(f x)
|
(f x)
|
||||||
0)
|
0)
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
(unless (path-for-some-system? p)
|
(unless (path-for-some-system? p)
|
||||||
(error "Predicate failed"))
|
(error "Predicate failed"))
|
||||||
(explode-path long-path)
|
(explode-path long-path)
|
||||||
|
|
||||||
(filename-extension p)
|
(filename-extension p)
|
||||||
(path-only long-path)
|
(path-only long-path)
|
||||||
(some-system-path->string long-path)
|
(some-system-path->string long-path)
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,13 @@
|
||||||
|
|
||||||
(: rotate : (All (A) ((Stream A) (Listof A) (Stream A) -> (Stream A))))
|
(: rotate : (All (A) ((Stream A) (Listof A) (Stream A) -> (Stream A))))
|
||||||
(define (rotate frnt rer accum)
|
(define (rotate frnt rer accum)
|
||||||
(let ([carrer (car rer)])
|
(let ([carrer (car rer)])
|
||||||
;; Manually expanded `stream-cons', and added type annotations
|
;; Manually expanded `stream-cons', and added type annotations
|
||||||
(if (empty-stream? frnt)
|
(if (empty-stream? frnt)
|
||||||
(stream-cons carrer accum)
|
(stream-cons carrer accum)
|
||||||
(stream-cons
|
(stream-cons
|
||||||
(stream-car frnt)
|
(stream-car frnt)
|
||||||
((inst rotate A)
|
((inst rotate A)
|
||||||
(stream-cdr frnt)
|
(stream-cdr frnt)
|
||||||
(cdr rer)
|
(cdr rer)
|
||||||
(box (lambda () (cons carrer accum))))))))
|
(box (lambda () (cons carrer accum))))))))
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#lang scheme/load
|
#lang scheme/load
|
||||||
|
|
||||||
(module for-broken typed-scheme
|
(module for-broken typed-scheme
|
||||||
|
|
||||||
(define-typed-struct type ())
|
(define-typed-struct type ())
|
||||||
|
|
||||||
(provide (all-defined-out)))
|
(provide (all-defined-out)))
|
||||||
|
|
||||||
(module broken typed-scheme
|
(module broken typed-scheme
|
||||||
|
|
||||||
(require (prefix-in t: 'for-broken))
|
(require (prefix-in t: 'for-broken))
|
||||||
(define-typed-struct binding ([type : t:type]))
|
(define-typed-struct binding ([type : t:type]))
|
||||||
;; Comment out the below and it works fine.
|
;; Comment out the below and it works fine.
|
||||||
|
|
|
@ -97,5 +97,5 @@ xxx6-y
|
||||||
(list* 1 2 3)
|
(list* 1 2 3)
|
||||||
(ann (list* 1 2 3 (list)) (Pair Number (Listof Integer)))
|
(ann (list* 1 2 3 (list)) (Pair Number (Listof Integer)))
|
||||||
|
|
||||||
((lambda (x) 1) 1)
|
((lambda (x) 1) 1)
|
||||||
((lambda (x y) 1) 1 2)
|
((lambda (x y) 1) 1 2)
|
||||||
|
|
|
@ -15,4 +15,4 @@
|
||||||
(loop 10000000 0))
|
(loop 10000000 0))
|
||||||
(parameterize ([current-output-port (open-output-nowhere)])
|
(parameterize ([current-output-port (open-output-nowhere)])
|
||||||
(time (bar 0)))
|
(time (bar 0)))
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
(inst map-with-funcs Integer Integer)
|
(inst map-with-funcs Integer Integer)
|
||||||
|
|
||||||
(map-with-funcs
|
(map-with-funcs
|
||||||
(lambda: ([x : Integer] [y : Integer]) (+ x y))
|
(lambda: ([x : Integer] [y : Integer]) (+ x y))
|
||||||
(lambda: ([x : Integer] [y : Integer]) (- x y)) )
|
(lambda: ([x : Integer] [y : Integer]) (- x y)) )
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
(define: x : (Vectorof Number) (build-vector 5 (lambda: ([x : Number]) 0)))
|
(define: x : (Vectorof Number) (build-vector 5 (lambda: ([x : Number]) 0)))
|
||||||
(define: y : Number (vector-ref x 1))
|
(define: y : Number (vector-ref x 1))
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#lang scheme/base
|
#lang scheme/base
|
||||||
|
|
||||||
(require
|
(require
|
||||||
"test-utils.ss"
|
"test-utils.ss"
|
||||||
"typecheck-tests.ss" ;;fail
|
"typecheck-tests.ss" ;;fail
|
||||||
|
|
||||||
"subtype-tests.ss" ;; pass
|
"subtype-tests.ss" ;; pass
|
||||||
"type-equal-tests.ss" ;; pass
|
"type-equal-tests.ss" ;; pass
|
||||||
"remove-intersect-tests.ss" ;; pass
|
"remove-intersect-tests.ss" ;; pass
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
"subst-tests.ss" ;; pass
|
"subst-tests.ss" ;; pass
|
||||||
"infer-tests.ss" ;; pass
|
"infer-tests.ss" ;; pass
|
||||||
"type-annotation-test.ss" ;; pass
|
"type-annotation-test.ss" ;; pass
|
||||||
|
|
||||||
"module-tests.ss" ;; pass
|
"module-tests.ss" ;; pass
|
||||||
"contract-tests.ss"
|
"contract-tests.ss"
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@
|
||||||
(infer-param infer)
|
(infer-param infer)
|
||||||
|
|
||||||
(define unit-tests
|
(define unit-tests
|
||||||
(make-test-suite
|
(make-test-suite
|
||||||
"Unit Tests"
|
"Unit Tests"
|
||||||
(for/list ([f (list
|
(for/list ([f (list
|
||||||
typecheck-tests
|
typecheck-tests
|
||||||
subtype-tests
|
subtype-tests
|
||||||
type-equal-tests
|
type-equal-tests
|
||||||
restrict-tests
|
restrict-tests
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#lang scheme/base
|
#lang scheme/base
|
||||||
|
|
||||||
(require "test-utils.ss"
|
(require "test-utils.ss"
|
||||||
(for-syntax scheme/base)
|
(for-syntax scheme/base)
|
||||||
(for-template scheme/base)
|
(for-template scheme/base)
|
||||||
(private type-contract)
|
(private type-contract)
|
||||||
(rep type-rep filter-rep object-rep)
|
(rep type-rep filter-rep object-rep)
|
||||||
(types utils union convenience)
|
(types utils union convenience)
|
||||||
(utils tc-utils)
|
(utils tc-utils)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
[fv-t (-poly (b c d e) (-v a)) a]
|
[fv-t (-poly (b c d e) (-v a)) a]
|
||||||
[fv-t (-mu a (-lst a))]
|
[fv-t (-mu a (-lst a))]
|
||||||
[fv-t (-mu a (-lst (-pair a (-v b)))) b]
|
[fv-t (-mu a (-lst (-pair a (-v b)))) b]
|
||||||
|
|
||||||
[fv-t (->* null (-v a) -Number) a] ;; check that a is CONTRAVARIANT
|
[fv-t (->* null (-v a) -Number) a] ;; check that a is CONTRAVARIANT
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
(define (f t1 t2) (infer t1 t2 (fv t1) (fv t1)))
|
(define (f t1 t2) (infer t1 t2 (fv t1) (fv t1)))
|
||||||
|
|
||||||
(define-syntax-rule (i2-f t1 t2)
|
(define-syntax-rule (i2-f t1 t2)
|
||||||
(test-false (format "~a ~a" t1 t2)
|
(test-false (format "~a ~a" t1 t2)
|
||||||
(f t1 t2)))
|
(f t1 t2)))
|
||||||
#|
|
#|
|
||||||
(define (i2-tests)
|
(define (i2-tests)
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
[i2-t (-lst (-v a)) (-pair N (-pair N (-val null))) ('a N)]
|
[i2-t (-lst (-v a)) (-pair N (-pair N (-val null))) ('a N)]
|
||||||
[i2-t (-lst (-v a)) (-pair N (-pair B (-val null))) ('a (Un N B))]
|
[i2-t (-lst (-v a)) (-pair N (-pair B (-val null))) ('a (Un N B))]
|
||||||
[i2-t Univ (Un N B)]
|
[i2-t Univ (Un N B)]
|
||||||
|
|
||||||
[i2-t ((-v a) . -> . (-v b)) (-> N N) ('b N) ('a N)]
|
[i2-t ((-v a) . -> . (-v b)) (-> N N) ('b N) ('a N)]
|
||||||
[i2-l (list (-v a) (-v a) (-v b)) (list (Un (-val 1) (-val 2)) N N) '(a b) ('b N) ('a N)]
|
[i2-l (list (-v a) (-v a) (-v b)) (list (Un (-val 1) (-val 2)) N N) '(a b) ('b N) ('a N)]
|
||||||
[i2-l (list (-> (-v a) Univ) (-lst (-v a))) (list (-> N (Un N B)) (-lst N)) '(a) ('a N)]
|
[i2-l (list (-> (-v a) Univ) (-lst (-v a))) (list (-> N (Un N B)) (-lst N)) '(a) ('a N)]
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
;; The solution is to add the identifiers to the table at phase 0.
|
;; The solution is to add the identifiers to the table at phase 0.
|
||||||
;; We do this by going through the table, constructing new identifiers based on the symbol
|
;; We do this by going through the table, constructing new identifiers based on the symbol
|
||||||
;; of the old identifier.
|
;; of the old identifier.
|
||||||
;; This relies on the identifiers being bound at phase 0 in this module (which they are,
|
;; This relies on the identifiers being bound at phase 0 in this module (which they are,
|
||||||
;; because we have a phase 0 require of "base-env.ss").
|
;; because we have a phase 0 require of "base-env.ss").
|
||||||
(for ([pr (type-alias-env-map cons)])
|
(for ([pr (type-alias-env-map cons)])
|
||||||
(let ([nm (car pr)]
|
(let ([nm (car pr)]
|
||||||
|
@ -61,9 +61,9 @@
|
||||||
(define B -Boolean)
|
(define B -Boolean)
|
||||||
(define Sym -Symbol)
|
(define Sym -Symbol)
|
||||||
|
|
||||||
(define (parse-type-tests)
|
(define (parse-type-tests)
|
||||||
(pt-tests
|
(pt-tests
|
||||||
"parse-type tests"
|
"parse-type tests"
|
||||||
[Number N]
|
[Number N]
|
||||||
[Any Univ]
|
[Any Univ]
|
||||||
[(List Number String) (-Tuple (list N -String))]
|
[(List Number String) (-Tuple (list N -String))]
|
||||||
|
@ -105,13 +105,13 @@
|
||||||
[#f (-val #f)]
|
[#f (-val #f)]
|
||||||
["foo" (-val "foo")]
|
["foo" (-val "foo")]
|
||||||
['(1 2 3) (-Tuple (map -val '(1 2 3)))]
|
['(1 2 3) (-Tuple (map -val '(1 2 3)))]
|
||||||
|
|
||||||
[(Listof Number) (make-Listof N)]
|
[(Listof Number) (make-Listof N)]
|
||||||
|
|
||||||
[a (-v a) (set-add initial-tvar-env 'a)]
|
[a (-v a) (set-add initial-tvar-env 'a)]
|
||||||
[(All (a ...) (a ... -> Number))
|
[(All (a ...) (a ... -> Number))
|
||||||
(-polydots (a) ((list) [a a] . ->... . N))]
|
(-polydots (a) ((list) [a a] . ->... . N))]
|
||||||
|
|
||||||
[(Any -> Boolean : Number) (make-pred-ty -Number)]
|
[(Any -> Boolean : Number) (make-pred-ty -Number)]
|
||||||
[(Any -> Boolean : #:+ (Number @ 0) #:- (! Number @ 0))
|
[(Any -> Boolean : #:+ (Number @ 0) #:- (! Number @ 0))
|
||||||
(make-pred-ty -Number)]
|
(make-pred-ty -Number)]
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
(t:-> -Number (t:-> -Number -Number))]
|
(t:-> -Number (t:-> -Number -Number))]
|
||||||
[(Integer -> (All (X) (X -> X)))
|
[(Integer -> (All (X) (X -> X)))
|
||||||
(t:-> -Integer (-poly (x) (t:-> x x)))]
|
(t:-> -Integer (-poly (x) (t:-> x x)))]
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
;; FIXME - add tests for parse-values-type, parse-tc-results
|
;; FIXME - add tests for parse-values-type, parse-tc-results
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
(require (for-syntax scheme/base scheme/require-transform)
|
(require (for-syntax scheme/base scheme/require-transform)
|
||||||
scheme/require-syntax)
|
scheme/require-syntax)
|
||||||
|
|
||||||
(define-for-syntax (splice-requires specs)
|
(define-for-syntax (splice-requires specs)
|
||||||
(define subs (map (compose cons expand-import) specs))
|
(define subs (map (compose cons expand-import) specs))
|
||||||
(values (apply append (map car subs)) (apply append (map cdr subs))))
|
(values (apply append (map car subs)) (apply append (map cdr subs))))
|
||||||
|
|
||||||
(define-syntax define-module
|
(define-syntax define-module
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ nm spec ...)
|
[(_ nm spec ...)
|
||||||
(define-syntax nm
|
(define-syntax nm
|
||||||
(make-require-transformer
|
(make-require-transformer
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
(types convenience subtype union remove-intersect)
|
(types convenience subtype union remove-intersect)
|
||||||
rackunit)
|
rackunit)
|
||||||
|
|
||||||
(define-syntax (over-tests stx)
|
(define-syntax (over-tests stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ [t1 t2 res] ...)
|
[(_ [t1 t2 res] ...)
|
||||||
#'(test-suite "Tests for intersect"
|
#'(test-suite "Tests for intersect"
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
(over-tests
|
(over-tests
|
||||||
[-Number -Integer #t]))
|
[-Number -Integer #t]))
|
||||||
|
|
||||||
(define-syntax (restr-tests stx)
|
(define-syntax (restr-tests stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ [t1 t2 res] ...)
|
[(_ [t1 t2 res] ...)
|
||||||
#'(test-suite "Tests for intersect"
|
#'(test-suite "Tests for intersect"
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
(infer-param infer)
|
(infer-param infer)
|
||||||
|
|
||||||
(define (restrict-tests)
|
(define (restrict-tests)
|
||||||
(restr-tests
|
(restr-tests
|
||||||
[-Number (Un -Number -Symbol) -Number]
|
[-Number (Un -Number -Symbol) -Number]
|
||||||
[-Number -Number -Number]
|
[-Number -Number -Number]
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
[(Un -Number -Boolean) (-mu a (Un -Number -Symbol (make-Listof a))) -Number]
|
[(Un -Number -Boolean) (-mu a (Un -Number -Symbol (make-Listof a))) -Number]
|
||||||
[(-mu x (Un -Number (make-Listof x))) (Un -Symbol -Number -Boolean) -Number]
|
[(-mu x (Un -Number (make-Listof x))) (Un -Symbol -Number -Boolean) -Number]
|
||||||
[(Un -Number -String -Symbol -Boolean) -Number -Number]
|
[(Un -Number -String -Symbol -Boolean) -Number -Number]
|
||||||
|
|
||||||
[(-lst -Number) (-pair Univ Univ) (-pair -Number (-lst -Number))]
|
[(-lst -Number) (-pair Univ Univ) (-pair -Number (-lst -Number))]
|
||||||
;; FIXME
|
;; FIXME
|
||||||
#;
|
#;
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
[-Sexp -Listof (-lst -Sexp)]
|
[-Sexp -Listof (-lst -Sexp)]
|
||||||
))
|
))
|
||||||
|
|
||||||
(define-syntax (remo-tests stx)
|
(define-syntax (remo-tests stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ [t1 t2 res] ...)
|
[(_ [t1 t2 res] ...)
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
[(-mu x (Un -Number -Symbol (make-Listof x))) -Number (Un -Symbol (make-Listof (-mu x (Un -Number -Symbol (make-Listof x)))))]
|
[(-mu x (Un -Number -Symbol (make-Listof x))) -Number (Un -Symbol (make-Listof (-mu x (Un -Number -Symbol (make-Listof x)))))]
|
||||||
[(-mu x (Un -Number -Symbol -Boolean (make-Listof x))) -Number (Un -Symbol -Boolean (make-Listof (-mu x (Un -Number -Symbol -Boolean (make-Listof x)))))]
|
[(-mu x (Un -Number -Symbol -Boolean (make-Listof x))) -Number (Un -Symbol -Boolean (make-Listof (-mu x (Un -Number -Symbol -Boolean (make-Listof x)))))]
|
||||||
[(Un (-val #f) (-mu x (Un -Number -Symbol (make-Listof (-v x)))))
|
[(Un (-val #f) (-mu x (Un -Number -Symbol (make-Listof (-v x)))))
|
||||||
(Un -Boolean -Number)
|
(Un -Boolean -Number)
|
||||||
(Un -Symbol (make-Listof (-mu x (Un -Number -Symbol (make-Listof x)))))]
|
(Un -Symbol (make-Listof (-mu x (Un -Number -Symbol (make-Listof x)))))]
|
||||||
[(Un (-val 'foo) (-val 6)) (Un -Number -Symbol) (Un)]
|
[(Un (-val 'foo) (-val 6)) (Un -Number -Symbol) (Un)]
|
||||||
[(-> (Un -Symbol -Number) -Number) (-> -Number -Number) (Un)]
|
[(-> (Un -Symbol -Number) -Number) (-> -Number -Number) (Un)]
|
||||||
|
@ -64,19 +64,19 @@
|
||||||
[(-pair -Number (-v a)) (-pair Univ Univ) (Un)]
|
[(-pair -Number (-v a)) (-pair Univ Univ) (Un)]
|
||||||
))
|
))
|
||||||
|
|
||||||
(define-go
|
(define-go
|
||||||
restrict-tests
|
restrict-tests
|
||||||
remove-tests
|
remove-tests
|
||||||
overlap-tests)
|
overlap-tests)
|
||||||
|
|
||||||
(define x1
|
(define x1
|
||||||
(-mu list-rec
|
(-mu list-rec
|
||||||
(Un
|
(Un
|
||||||
(-val '())
|
(-val '())
|
||||||
(-pair (-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x)))
|
(-pair (-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x)))
|
||||||
list-rec))))
|
list-rec))))
|
||||||
(define x2
|
(define x2
|
||||||
(Un (-val '())
|
(Un (-val '())
|
||||||
(-pair (-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x)))
|
(-pair (-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x)))
|
||||||
(-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x))))))
|
(-mu x (Un -Boolean -Number -String -Symbol (-val '()) (-pair x x))))))
|
||||||
(provide remove-tests restrict-tests overlap-tests)
|
(provide remove-tests restrict-tests overlap-tests)
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots null -Number (-v a) 'a))) (-Number -Boolean . -> . -Number))
|
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots null -Number (-v a) 'a))) (-Number -Boolean . -> . -Number))
|
||||||
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v a) 'a))) (-String -Number -Boolean . -> . -Number))
|
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v a) 'a))) (-String -Number -Boolean . -> . -Number))
|
||||||
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'a))) (-String (-v b) (-v b) . -> . -Number))
|
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'a))) (-String (-v b) (-v b) . -> . -Number))
|
||||||
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b)))
|
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b)))
|
||||||
(make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b))))))
|
(make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b))))))
|
||||||
|
|
||||||
(define-go subst-tests)
|
(define-go subst-tests)
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
[(Un (-val 6) (-val 7)) -Number]
|
[(Un (-val 6) (-val 7)) -Number]
|
||||||
[(Un (-val #f) (Un (-val 6) (-val 7))) (Un -Number (Un -Boolean -Symbol))]
|
[(Un (-val #f) (Un (-val 6) (-val 7))) (Un -Number (Un -Boolean -Symbol))]
|
||||||
[(Un (-val #f) (Un (-val 6) (-val 7))) (-mu x (Un -Number (Un -Boolean -Symbol)))]
|
[(Un (-val #f) (Un (-val 6) (-val 7))) (-mu x (Un -Number (Un -Boolean -Symbol)))]
|
||||||
[(Un -Number (-val #f) (-mu x (Un -Number -Symbol (make-Listof x))))
|
[(Un -Number (-val #f) (-mu x (Un -Number -Symbol (make-Listof x))))
|
||||||
(-mu x (Un -Number -Symbol -Boolean (make-Listof x)))]
|
(-mu x (Un -Number -Symbol -Boolean (make-Listof x)))]
|
||||||
;; sexps vs list*s of nums
|
;; sexps vs list*s of nums
|
||||||
[(-mu x (Un -Number -Symbol (make-Listof x))) (-mu x (Un -Number -Symbol -Boolean (make-Listof x)))]
|
[(-mu x (Un -Number -Symbol (make-Listof x))) (-mu x (Un -Number -Symbol -Boolean (make-Listof x)))]
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
;; polymorphic types
|
;; polymorphic types
|
||||||
[(-poly (t) (-> t t)) (-poly (s) (-> s s))]
|
[(-poly (t) (-> t t)) (-poly (s) (-> s s))]
|
||||||
[FAIL (make-Listof -Number) (-poly (t) (make-Listof t))]
|
[FAIL (make-Listof -Number) (-poly (t) (make-Listof t))]
|
||||||
[(-poly (a) (make-Listof (-v a))) (make-Listof -Number)] ;;
|
[(-poly (a) (make-Listof (-v a))) (make-Listof -Number)] ;;
|
||||||
[(-poly (a) -Number) -Number]
|
[(-poly (a) -Number) -Number]
|
||||||
|
|
||||||
[(-val 6) -Number]
|
[(-val 6) -Number]
|
||||||
|
@ -109,11 +109,11 @@
|
||||||
[(-Number) a]))
|
[(-Number) a]))
|
||||||
(cl-> [() (-pair -Number (-v b))]
|
(cl-> [() (-pair -Number (-v b))]
|
||||||
[(-Number) (-pair -Number (-v b))])]
|
[(-Number) (-pair -Number (-v b))])]
|
||||||
|
|
||||||
[(-values (list -Number)) (-values (list Univ))]
|
[(-values (list -Number)) (-values (list Univ))]
|
||||||
|
|
||||||
[(-poly (b) ((Un (make-Base 'foo #'dummy values #'values)
|
[(-poly (b) ((Un (make-Base 'foo #'dummy values #'values)
|
||||||
(-struct 'bar #f
|
(-struct 'bar #f
|
||||||
(list (make-fld -Number #'values #f) (make-fld b #'values #f))
|
(list (make-fld -Number #'values #f) (make-fld b #'values #f))
|
||||||
#'values))
|
#'values))
|
||||||
. -> . (-lst b)))
|
. -> . (-lst b)))
|
||||||
|
@ -121,12 +121,12 @@
|
||||||
. -> . (-lst (-pair -Number (-v a))))]
|
. -> . (-lst (-pair -Number (-v a))))]
|
||||||
[(-poly (b) ((-struct 'bar #f (list (make-fld -Number #'values #f) (make-fld b #'values #f)) #'values) . -> . (-lst b)))
|
[(-poly (b) ((-struct 'bar #f (list (make-fld -Number #'values #f) (make-fld b #'values #f)) #'values) . -> . (-lst b)))
|
||||||
((-struct 'bar #f (list (make-fld -Number #'values #f) (make-fld (-pair -Number (-v a)) #'values #f)) #'values) . -> . (-lst (-pair -Number (-v a))))]
|
((-struct 'bar #f (list (make-fld -Number #'values #f) (make-fld (-pair -Number (-v a)) #'values #f)) #'values) . -> . (-lst (-pair -Number (-v a))))]
|
||||||
|
|
||||||
[(-poly (a) (a . -> . (make-Listof a))) ((-v b) . -> . (make-Listof (-v b)))]
|
[(-poly (a) (a . -> . (make-Listof a))) ((-v b) . -> . (make-Listof (-v b)))]
|
||||||
[(-poly (a) (a . -> . (make-Listof a))) ((-pair -Number (-v b)) . -> . (make-Listof (-pair -Number (-v b))))]
|
[(-poly (a) (a . -> . (make-Listof a))) ((-pair -Number (-v b)) . -> . (make-Listof (-pair -Number (-v b))))]
|
||||||
|
|
||||||
(FAIL (-poly (a b) (-> a a)) (-poly (a b) (-> a b)))
|
(FAIL (-poly (a b) (-> a a)) (-poly (a b) (-> a b)))
|
||||||
|
|
||||||
;; polymorphic function types should be subtypes of the function top
|
;; polymorphic function types should be subtypes of the function top
|
||||||
[(-poly (a) (a . -> . a)) top-func]
|
[(-poly (a) (a . -> . a)) top-func]
|
||||||
(FAIL (-> Univ) (null Univ . ->* . Univ))
|
(FAIL (-> Univ) (null Univ . ->* . Univ))
|
||||||
|
@ -137,5 +137,5 @@
|
||||||
[(-struct 'a #f (list (make-fld -String #'values #f)) #'values) (-struct 'a #f (list (make-fld Univ #'values #f)) #'values)]
|
[(-struct 'a #f (list (make-fld -String #'values #f)) #'values) (-struct 'a #f (list (make-fld Univ #'values #f)) #'values)]
|
||||||
))
|
))
|
||||||
|
|
||||||
(define-go
|
(define-go
|
||||||
subtype-tests)
|
subtype-tests)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
(define (run . ts)
|
(define (run . ts)
|
||||||
(run-tests (mk-suite ts)))
|
(run-tests (mk-suite ts)))
|
||||||
|
|
||||||
(define (test/gui suite)
|
(define (test/gui suite)
|
||||||
(((dynamic-require 'rackunit/private/gui/gui 'make-gui-runner))
|
(((dynamic-require 'rackunit/private/gui/gui 'make-gui-runner))
|
||||||
suite))
|
suite))
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
(define-syntax (define-go stx)
|
(define-syntax (define-go stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ args ...)
|
[(_ args ...)
|
||||||
(with-syntax
|
(with-syntax
|
||||||
([go (datum->syntax stx 'go)]
|
([go (datum->syntax stx 'go)]
|
||||||
[go/gui (datum->syntax stx 'go/gui)]
|
[go/gui (datum->syntax stx 'go/gui)]
|
||||||
[(tmps ...) (generate-temporaries #'(args ...))])
|
[(tmps ...) (generate-temporaries #'(args ...))])
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
(provide type-annotation-tests)
|
(provide type-annotation-tests)
|
||||||
|
|
||||||
(define-syntax-rule (tat ann-stx ty)
|
(define-syntax-rule (tat ann-stx ty)
|
||||||
(check-tc-result-equal? (format "~a" (quote ann-stx))
|
(check-tc-result-equal? (format "~a" (quote ann-stx))
|
||||||
(type-ascription (let ([ons (current-namespace)]
|
(type-ascription (let ([ons (current-namespace)]
|
||||||
[ns (make-base-namespace)])
|
[ns (make-base-namespace)])
|
||||||
(parameterize ([current-namespace ns])
|
(parameterize ([current-namespace ns])
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
ty))
|
ty))
|
||||||
|
|
||||||
(define (type-annotation-tests)
|
(define (type-annotation-tests)
|
||||||
(test-suite
|
(test-suite
|
||||||
"Type Annotation tests"
|
"Type Annotation tests"
|
||||||
;; FIXME - ask Ryan
|
;; FIXME - ask Ryan
|
||||||
(tat (ann foo : Number) (ret -Number (make-NoFilter) (make-NoObject)))
|
(tat (ann foo : Number) (ret -Number (make-NoFilter) (make-NoObject)))
|
||||||
|
|
|
@ -36,14 +36,14 @@
|
||||||
[(Un -Number -Symbol -Boolean) (Un -Boolean (Un -Symbol -Number))]
|
[(Un -Number -Symbol -Boolean) (Un -Boolean (Un -Symbol -Number))]
|
||||||
[(Un -Number -Symbol) (Un -Symbol -Number)]
|
[(Un -Number -Symbol) (Un -Symbol -Number)]
|
||||||
[(-poly (x) (-> (Un -Symbol -Number) x)) (-poly (xyz) (-> (Un -Number -Symbol) xyz))]
|
[(-poly (x) (-> (Un -Symbol -Number) x)) (-poly (xyz) (-> (Un -Number -Symbol) xyz))]
|
||||||
[(-mu x (Un -Number -Symbol x)) (-mu y (Un -Number -Symbol y))]
|
[(-mu x (Un -Number -Symbol x)) (-mu y (Un -Number -Symbol y))]
|
||||||
;; found bug
|
;; found bug
|
||||||
[FAIL (Un (-mu heap-node
|
[FAIL (Un (-mu heap-node
|
||||||
(-struct 'heap-node #f
|
(-struct 'heap-node #f
|
||||||
(map fld* (list (-base 'comparator) -Number (-v a) (Un heap-node (-base 'heap-empty))))
|
(map fld* (list (-base 'comparator) -Number (-v a) (Un heap-node (-base 'heap-empty))))
|
||||||
#'values))
|
#'values))
|
||||||
(-base 'heap-empty))
|
(-base 'heap-empty))
|
||||||
(Un (-mu heap-node
|
(Un (-mu heap-node
|
||||||
(-struct 'heap-node #f
|
(-struct 'heap-node #f
|
||||||
(map fld* (list (-base 'comparator) -Number (-pair -Number -Number) (Un heap-node (-base 'heap-empty)))) #'values))
|
(map fld* (list (-base 'comparator) -Number (-pair -Number -Number) (Un heap-node (-base 'heap-empty)))) #'values))
|
||||||
(-base 'heap-empty))]))
|
(-base 'heap-empty))]))
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
base-env-indexing base-special-env))
|
base-env-indexing base-special-env))
|
||||||
racket/file
|
racket/file
|
||||||
(for-template
|
(for-template
|
||||||
|
|
||||||
(base-env #;base-env base-types base-types-extra
|
(base-env #;base-env base-types base-types-extra
|
||||||
#;base-env-numeric
|
#;base-env-numeric
|
||||||
base-special-env
|
base-special-env
|
||||||
base-env-indexing))
|
base-env-indexing))
|
||||||
(for-syntax syntax/kerncase syntax/parse))
|
(for-syntax syntax/kerncase syntax/parse))
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
(prefix-in n: (base-env base-env-numeric)))
|
(prefix-in n: (base-env base-env-numeric)))
|
||||||
|
|
||||||
(provide typecheck-tests g tc-expr/expand)
|
(provide typecheck-tests g tc-expr/expand)
|
||||||
|
|
||||||
(b:init) (n:init) (initialize-structs) (initialize-indexing) (initialize-special)
|
(b:init) (n:init) (initialize-structs) (initialize-indexing) (initialize-special)
|
||||||
|
|
||||||
(define N -Number)
|
(define N -Number)
|
||||||
|
@ -93,12 +93,12 @@
|
||||||
(define-syntax (tc-e stx)
|
(define-syntax (tc-e stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ expr ty) (syntax/loc stx (tc-e expr #:ret (ret ty)))]
|
[(_ expr ty) (syntax/loc stx (tc-e expr #:ret (ret ty)))]
|
||||||
[(_ expr #:proc p)
|
[(_ expr #:proc p)
|
||||||
(quasisyntax/loc stx
|
(quasisyntax/loc stx
|
||||||
(let-values ([(t e) (tc-expr/expand/values expr)])
|
(let-values ([(t e) (tc-expr/expand/values expr)])
|
||||||
#,(quasisyntax/loc stx (check-tc-result-equal? (format "~a ~s" #,(syntax-line stx) 'expr) (t) (p e)))))]
|
#,(quasisyntax/loc stx (check-tc-result-equal? (format "~a ~s" #,(syntax-line stx) 'expr) (t) (p e)))))]
|
||||||
[(_ expr #:ret r)
|
[(_ expr #:ret r)
|
||||||
(quasisyntax/loc stx
|
(quasisyntax/loc stx
|
||||||
(check-tc-result-equal? (format "~a ~a" #,(syntax-line stx) 'expr) (tc-expr/expand expr) r))]
|
(check-tc-result-equal? (format "~a ~a" #,(syntax-line stx) 'expr) (tc-expr/expand expr) r))]
|
||||||
[(_ expr ty f o) (syntax/loc stx (tc-e expr #:ret (ret ty f o)))]))
|
[(_ expr ty f o) (syntax/loc stx (tc-e expr #:ret (ret ty f o)))]))
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ expr)
|
[(_ expr)
|
||||||
(test-exn (format "~a" 'expr)
|
(test-exn (format "~a" 'expr)
|
||||||
exn:fail:syntax?
|
exn:fail:syntax?
|
||||||
(lambda () (tc-expr/expand expr)))]))
|
(lambda () (tc-expr/expand expr)))]))
|
||||||
|
|
||||||
(define-syntax-class (let-name n)
|
(define-syntax-class (let-name n)
|
||||||
|
@ -136,12 +136,12 @@
|
||||||
e]))
|
e]))
|
||||||
|
|
||||||
(define (typecheck-tests)
|
(define (typecheck-tests)
|
||||||
(test-suite
|
(test-suite
|
||||||
"Typechecker tests"
|
"Typechecker tests"
|
||||||
#reader typed-scheme/typed-reader
|
#reader typed-scheme/typed-reader
|
||||||
(test-suite
|
(test-suite
|
||||||
"tc-expr tests"
|
"tc-expr tests"
|
||||||
|
|
||||||
[tc-e
|
[tc-e
|
||||||
(let: ([x : (U Number (cons Number Number)) (cons 3 4)])
|
(let: ([x : (U Number (cons Number Number)) (cons 3 4)])
|
||||||
(if (pair? x)
|
(if (pair? x)
|
||||||
|
@ -200,7 +200,7 @@
|
||||||
[tc-e/t (case-lambda: [([a : Number] [b : Number]) (+ a b)]) (t:-> N N N)]
|
[tc-e/t (case-lambda: [([a : Number] [b : Number]) (+ a b)]) (t:-> N N N)]
|
||||||
[tc-e (let: ([x : Number 5]) x) N]
|
[tc-e (let: ([x : Number 5]) x) N]
|
||||||
[tc-e (let-values ([(x) 4]) (+ x 1)) -PosIndex]
|
[tc-e (let-values ([(x) 4]) (+ x 1)) -PosIndex]
|
||||||
[tc-e (let-values ([(#{x : Number} #{y : Boolean}) (values 3 #t)]) (and (= x 1) (not y)))
|
[tc-e (let-values ([(#{x : Number} #{y : Boolean}) (values 3 #t)]) (and (= x 1) (not y)))
|
||||||
#:proc (syntax-parser [(_ ([(_ y) . _]) . _) (ret -Boolean (-FS -top -top))])]
|
#:proc (syntax-parser [(_ ([(_ y) . _]) . _) (ret -Boolean (-FS -top -top))])]
|
||||||
[tc-e/t (values 3) -PosByte]
|
[tc-e/t (values 3) -PosByte]
|
||||||
[tc-e (values) #:ret (ret null)]
|
[tc-e (values) #:ret (ret null)]
|
||||||
|
@ -247,7 +247,7 @@
|
||||||
[tc-e/t (if #f #f #t) (t:Un (-val #t))]
|
[tc-e/t (if #f #f #t) (t:Un (-val #t))]
|
||||||
[tc-e (when #f 3) -Void]
|
[tc-e (when #f 3) -Void]
|
||||||
[tc-e/t '() (-val '())]
|
[tc-e/t '() (-val '())]
|
||||||
[tc-e/t (let: ([x : (Listof Number) '(1)])
|
[tc-e/t (let: ([x : (Listof Number) '(1)])
|
||||||
(cond [(pair? x) 1]
|
(cond [(pair? x) 1]
|
||||||
[(null? x) 1]))
|
[(null? x) 1]))
|
||||||
-One]
|
-One]
|
||||||
|
@ -258,74 +258,74 @@
|
||||||
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '(4)) N]
|
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '(4)) N]
|
||||||
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '(4 6 7)) N]
|
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '(4 6 7)) N]
|
||||||
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '()) N]
|
[tc-e (apply (lambda: ([x : Number] . [y : Number *]) (car y)) 3 '()) N]
|
||||||
|
|
||||||
[tc-e/t (lambda: ([x : Number] . [y : Boolean *]) (car y)) (->* (list N) B B)]
|
[tc-e/t (lambda: ([x : Number] . [y : Boolean *]) (car y)) (->* (list N) B B)]
|
||||||
[tc-e ((lambda: ([x : Number] . [y : Boolean *]) (car y)) 3) B]
|
[tc-e ((lambda: ([x : Number] . [y : Boolean *]) (car y)) 3) B]
|
||||||
[tc-e (apply (lambda: ([x : Number] . [y : Boolean *]) (car y)) 3 '(#f)) B]
|
[tc-e (apply (lambda: ([x : Number] . [y : Boolean *]) (car y)) 3 '(#f)) B]
|
||||||
|
|
||||||
[tc-e/t (let: ([x : Number 3])
|
[tc-e/t (let: ([x : Number 3])
|
||||||
(when (number? x) #t))
|
(when (number? x) #t))
|
||||||
(-val #t)]
|
(-val #t)]
|
||||||
[tc-e (let: ([x : Number 3])
|
[tc-e (let: ([x : Number 3])
|
||||||
(when (boolean? x) #t))
|
(when (boolean? x) #t))
|
||||||
-Void]
|
-Void]
|
||||||
|
|
||||||
[tc-e/t (let: ([x : Any 3])
|
[tc-e/t (let: ([x : Any 3])
|
||||||
(if (list? x)
|
(if (list? x)
|
||||||
(begin (car x) 1)
|
(begin (car x) 1)
|
||||||
2))
|
2))
|
||||||
-PosByte]
|
-PosByte]
|
||||||
|
|
||||||
|
|
||||||
[tc-e (let: ([x : (U Number Boolean) 3])
|
[tc-e (let: ([x : (U Number Boolean) 3])
|
||||||
(if (not (boolean? x))
|
(if (not (boolean? x))
|
||||||
(add1 x)
|
(add1 x)
|
||||||
3))
|
3))
|
||||||
N]
|
N]
|
||||||
|
|
||||||
[tc-e (let ([x 1]) x) -One]
|
[tc-e (let ([x 1]) x) -One]
|
||||||
[tc-e (let ([x 1]) (boolean? x)) #:ret (ret -Boolean (-FS -bot -top))]
|
[tc-e (let ([x 1]) (boolean? x)) #:ret (ret -Boolean (-FS -bot -top))]
|
||||||
[tc-e (boolean? number?) #:ret (ret -Boolean (-FS -bot -top))]
|
[tc-e (boolean? number?) #:ret (ret -Boolean (-FS -bot -top))]
|
||||||
|
|
||||||
[tc-e (let: ([x : (Option Number) #f]) x) (t:Un N (-val #f))]
|
[tc-e (let: ([x : (Option Number) #f]) x) (t:Un N (-val #f))]
|
||||||
[tc-e (let: ([x : Any 12]) (not (not x))) -Boolean]
|
[tc-e (let: ([x : Any 12]) (not (not x))) -Boolean]
|
||||||
|
|
||||||
[tc-e (let: ([x : (Option Number) #f])
|
[tc-e (let: ([x : (Option Number) #f])
|
||||||
(if (let ([z 1]) x)
|
(if (let ([z 1]) x)
|
||||||
(add1 x)
|
(add1 x)
|
||||||
12))
|
12))
|
||||||
N]
|
N]
|
||||||
[tc-err (5 4)]
|
[tc-err (5 4)]
|
||||||
[tc-err (apply 5 '(2))]
|
[tc-err (apply 5 '(2))]
|
||||||
[tc-err (map (lambda: ([x : Any] [y : Any]) 1) '(1))]
|
[tc-err (map (lambda: ([x : Any] [y : Any]) 1) '(1))]
|
||||||
[tc-e (map add1 '(1)) (-pair -PosByte (-lst -PosByte))]
|
[tc-e (map add1 '(1)) (-pair -PosByte (-lst -PosByte))]
|
||||||
|
|
||||||
[tc-e/t (let ([x 5])
|
[tc-e/t (let ([x 5])
|
||||||
(if (eq? x 1)
|
(if (eq? x 1)
|
||||||
12
|
12
|
||||||
14))
|
14))
|
||||||
-PosByte]
|
-PosByte]
|
||||||
|
|
||||||
[tc-e (car (append (list 1 2) (list 3 4))) -PosByte]
|
[tc-e (car (append (list 1 2) (list 3 4))) -PosByte]
|
||||||
|
|
||||||
[tc-e
|
[tc-e
|
||||||
(let-syntax ([a
|
(let-syntax ([a
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ e) (let ([v 1]) e)])])
|
[(_ e) (let ([v 1]) e)])])
|
||||||
(let: ([v : String "a"])
|
(let: ([v : String "a"])
|
||||||
(string-append "foo" (a v))))
|
(string-append "foo" (a v))))
|
||||||
-String]
|
-String]
|
||||||
|
|
||||||
[tc-e (apply (plambda: (a) [x : a *] x) '(5)) (-lst -PosByte)]
|
[tc-e (apply (plambda: (a) [x : a *] x) '(5)) (-lst -PosByte)]
|
||||||
[tc-e (apply append (list '(1 2 3) '(4 5 6))) (-lst -PosByte)]
|
[tc-e (apply append (list '(1 2 3) '(4 5 6))) (-lst -PosByte)]
|
||||||
|
|
||||||
[tc-err ((case-lambda: [([x : Number]) x]
|
[tc-err ((case-lambda: [([x : Number]) x]
|
||||||
[([y : Number] [x : Number]) x])
|
[([y : Number] [x : Number]) x])
|
||||||
1 2 3)]
|
1 2 3)]
|
||||||
[tc-err ((case-lambda: [([x : Number]) x]
|
[tc-err ((case-lambda: [([x : Number]) x]
|
||||||
[([y : Number] [x : Number]) x])
|
[([y : Number] [x : Number]) x])
|
||||||
1 'foo)]
|
1 'foo)]
|
||||||
|
|
||||||
[tc-err (apply
|
[tc-err (apply
|
||||||
(case-lambda: [([x : Number]) x]
|
(case-lambda: [([x : Number]) x]
|
||||||
[([y : Number] [x : Number]) x])
|
[([y : Number] [x : Number]) x])
|
||||||
|
@ -334,38 +334,38 @@
|
||||||
(case-lambda: [([x : Number]) x]
|
(case-lambda: [([x : Number]) x]
|
||||||
[([y : Number] [x : Number]) x])
|
[([y : Number] [x : Number]) x])
|
||||||
'(1 foo))]
|
'(1 foo))]
|
||||||
|
|
||||||
[tc-e (let: ([x : Any #f])
|
[tc-e (let: ([x : Any #f])
|
||||||
(if (number? (let ([z 1]) x))
|
(if (number? (let ([z 1]) x))
|
||||||
(add1 x)
|
(add1 x)
|
||||||
12))
|
12))
|
||||||
N]
|
N]
|
||||||
|
|
||||||
[tc-e (let: ([x : (Option Number) #f])
|
[tc-e (let: ([x : (Option Number) #f])
|
||||||
(if x
|
(if x
|
||||||
(add1 x)
|
(add1 x)
|
||||||
12))
|
12))
|
||||||
N]
|
N]
|
||||||
|
|
||||||
|
|
||||||
[tc-e null #:ret (-path (-val null) #'null)]
|
[tc-e null #:ret (-path (-val null) #'null)]
|
||||||
|
|
||||||
[tc-e (let* ([sym 'squarf]
|
[tc-e (let* ([sym 'squarf]
|
||||||
[x (if (= 1 2) 3 sym)])
|
[x (if (= 1 2) 3 sym)])
|
||||||
x)
|
x)
|
||||||
(t:Un (-val 'squarf) -PosByte)]
|
(t:Un (-val 'squarf) -PosByte)]
|
||||||
|
|
||||||
[tc-e/t (if #t 1 2) -One]
|
[tc-e/t (if #t 1 2) -One]
|
||||||
|
|
||||||
|
|
||||||
;; eq? as predicate
|
;; eq? as predicate
|
||||||
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
||||||
(if (eq? x 'foo) 3 x))
|
(if (eq? x 'foo) 3 x))
|
||||||
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
||||||
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
||||||
(if (eq? 'foo x) 3 x))
|
(if (eq? 'foo x) 3 x))
|
||||||
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
||||||
|
|
||||||
[tc-err (let: ([x : (U String 'foo) 'foo])
|
[tc-err (let: ([x : (U String 'foo) 'foo])
|
||||||
(if (string=? x 'foo)
|
(if (string=? x 'foo)
|
||||||
"foo"
|
"foo"
|
||||||
|
@ -375,7 +375,7 @@
|
||||||
"foo"
|
"foo"
|
||||||
x))
|
x))
|
||||||
(t:Un -String (-val 5))]
|
(t:Un -String (-val 5))]
|
||||||
|
|
||||||
[tc-e (let* ([sym 'squarf]
|
[tc-e (let* ([sym 'squarf]
|
||||||
[x (if (= 1 2) 3 sym)])
|
[x (if (= 1 2) 3 sym)])
|
||||||
(if (eq? x sym) 3 x))
|
(if (eq? x sym) 3 x))
|
||||||
|
@ -393,7 +393,7 @@
|
||||||
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
[tc-e (let: ([x : (Un 'foo Number) 'foo])
|
||||||
(if (equal? 'foo x) 3 x))
|
(if (equal? 'foo x) 3 x))
|
||||||
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
#:proc (get-let-name x 0 (ret N (-FS -top -top)))]
|
||||||
|
|
||||||
[tc-e (let* ([sym 'squarf]
|
[tc-e (let* ([sym 'squarf]
|
||||||
[x (if (= 1 2) 3 sym)])
|
[x (if (= 1 2) 3 sym)])
|
||||||
(if (equal? x sym) 3 x))
|
(if (equal? x sym) 3 x))
|
||||||
|
@ -404,66 +404,66 @@
|
||||||
(if (equal? sym x) 3 x))
|
(if (equal? sym x) 3 x))
|
||||||
#:proc (syntax-parser [(_ _ (_ ([(x) _]) _))
|
#:proc (syntax-parser [(_ _ (_ ([(x) _]) _))
|
||||||
(ret -PosByte (-FS -top -top))])]
|
(ret -PosByte (-FS -top -top))])]
|
||||||
|
|
||||||
[tc-e (let: ([x : (Listof Symbol)'(a b c)])
|
[tc-e (let: ([x : (Listof Symbol)'(a b c)])
|
||||||
(cond [(memq 'a x) => car]
|
(cond [(memq 'a x) => car]
|
||||||
[else 'foo]))
|
[else 'foo]))
|
||||||
Sym]
|
Sym]
|
||||||
|
|
||||||
[tc-e (list 2 3 4) (-lst* -PosByte -PosByte -PosByte)]
|
[tc-e (list 2 3 4) (-lst* -PosByte -PosByte -PosByte)]
|
||||||
[tc-e (list 2 3 4 'a) (-lst* -PosByte -PosByte -PosByte (-val 'a))]
|
[tc-e (list 2 3 4 'a) (-lst* -PosByte -PosByte -PosByte (-val 'a))]
|
||||||
|
|
||||||
[tc-e `(1 2 ,(+ 3 4)) (-lst* -One -PosByte -PosIndex)]
|
[tc-e `(1 2 ,(+ 3 4)) (-lst* -One -PosByte -PosIndex)]
|
||||||
|
|
||||||
[tc-e (let: ([x : Any 1])
|
[tc-e (let: ([x : Any 1])
|
||||||
(when (and (list? x) (not (null? x)))
|
(when (and (list? x) (not (null? x)))
|
||||||
(car x)))
|
(car x)))
|
||||||
Univ]
|
Univ]
|
||||||
|
|
||||||
[tc-err (let: ([x : Any 3])
|
[tc-err (let: ([x : Any 3])
|
||||||
(car x))]
|
(car x))]
|
||||||
[tc-err (car #{3 : Any})]
|
[tc-err (car #{3 : Any})]
|
||||||
[tc-err (map #{3 : Any} #{12 : Any})]
|
[tc-err (map #{3 : Any} #{12 : Any})]
|
||||||
[tc-err (car 3)]
|
[tc-err (car 3)]
|
||||||
|
|
||||||
[tc-e/t (let: ([x : Any 1])
|
[tc-e/t (let: ([x : Any 1])
|
||||||
(if (and (list? x) (not (null? x)))
|
(if (and (list? x) (not (null? x)))
|
||||||
x
|
x
|
||||||
'foo))
|
'foo))
|
||||||
(t:Un (-val 'foo) (-pair Univ (-lst Univ)))]
|
(t:Un (-val 'foo) (-pair Univ (-lst Univ)))]
|
||||||
|
|
||||||
[tc-e (cadr (cadr (list 1 (list 1 2 3) 3))) -PosByte]
|
[tc-e (cadr (cadr (list 1 (list 1 2 3) 3))) -PosByte]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; tests for and
|
;;; tests for and
|
||||||
[tc-e (let: ([x : Any 1]) (and (number? x) (boolean? x)))
|
[tc-e (let: ([x : Any 1]) (and (number? x) (boolean? x)))
|
||||||
#:ret (ret B (-FS -bot -top))]
|
#:ret (ret B (-FS -bot -top))]
|
||||||
[tc-e (let: ([x : Any 1]) (and (number? x) x))
|
[tc-e (let: ([x : Any 1]) (and (number? x) x))
|
||||||
#:proc (get-let-name x 0 (ret (t:Un N (-val #f)) (-FS -top -top)))]
|
#:proc (get-let-name x 0 (ret (t:Un N (-val #f)) (-FS -top -top)))]
|
||||||
[tc-e (let: ([x : Any 1]) (and x (boolean? x)))
|
[tc-e (let: ([x : Any 1]) (and x (boolean? x)))
|
||||||
#:proc (get-let-name x 0 (ret -Boolean (-FS -top -top)))]
|
#:proc (get-let-name x 0 (ret -Boolean (-FS -top -top)))]
|
||||||
|
|
||||||
[tc-e/t (let: ([x : Any 3])
|
[tc-e/t (let: ([x : Any 3])
|
||||||
(if (and (list? x) (not (null? x)))
|
(if (and (list? x) (not (null? x)))
|
||||||
(begin (car x) 1) 2))
|
(begin (car x) 1) 2))
|
||||||
-PosByte]
|
-PosByte]
|
||||||
|
|
||||||
;; set! tests
|
;; set! tests
|
||||||
[tc-e (let: ([x : Any 3])
|
[tc-e (let: ([x : Any 3])
|
||||||
(set! x '(1 2 3))
|
(set! x '(1 2 3))
|
||||||
(if (number? x) x 2))
|
(if (number? x) x 2))
|
||||||
Univ]
|
Univ]
|
||||||
|
|
||||||
;; or tests - doesn't do anything good yet
|
;; or tests - doesn't do anything good yet
|
||||||
|
|
||||||
#;
|
#;
|
||||||
[tc-e (let: ([x : Any 3])
|
[tc-e (let: ([x : Any 3])
|
||||||
(if (or (boolean? x) (number? x))
|
(if (or (boolean? x) (number? x))
|
||||||
(if (boolean? x) 12 x)
|
(if (boolean? x) 12 x)
|
||||||
47))
|
47))
|
||||||
Univ]
|
Univ]
|
||||||
|
|
||||||
;; test for fake or
|
;; test for fake or
|
||||||
[tc-e (let: ([x : Any 1])
|
[tc-e (let: ([x : Any 1])
|
||||||
(if (if (number? x)
|
(if (if (number? x)
|
||||||
|
@ -487,13 +487,13 @@
|
||||||
(boolean? x))
|
(boolean? x))
|
||||||
(if (boolean? x) 1 x)
|
(if (boolean? x) 1 x)
|
||||||
4))
|
4))
|
||||||
#:proc (get-let-name
|
#:proc (get-let-name
|
||||||
x 0
|
x 0
|
||||||
(ret Univ
|
(ret Univ
|
||||||
(-FS
|
(-FS
|
||||||
-top
|
-top
|
||||||
(-and (make-NotTypeFilter -Boolean null #'x) (make-TypeFilter (-val #f) null #'x)))))]
|
(-and (make-NotTypeFilter -Boolean null #'x) (make-TypeFilter (-val #f) null #'x)))))]
|
||||||
|
|
||||||
;; T-AbsPred
|
;; T-AbsPred
|
||||||
[tc-e/t (let ([p? (lambda: ([x : Any]) (number? x))])
|
[tc-e/t (let ([p? (lambda: ([x : Any]) (number? x))])
|
||||||
(lambda: ([x : Any]) (if (p? x) (add1 x) (add1 12))))
|
(lambda: ([x : Any]) (if (p? x) (add1 x) (add1 12))))
|
||||||
|
@ -522,9 +522,9 @@
|
||||||
[p? (lambda: ([x : Any]) z)])
|
[p? (lambda: ([x : Any]) z)])
|
||||||
(lambda: ([x : Any]) (if (p? x) x 12)))
|
(lambda: ([x : Any]) (if (p? x) x 12)))
|
||||||
(t:-> Univ Univ)]
|
(t:-> Univ Univ)]
|
||||||
|
|
||||||
[tc-e (not 1) #:ret (ret B (-FS -bot -top))]
|
[tc-e (not 1) #:ret (ret B (-FS -bot -top))]
|
||||||
|
|
||||||
[tc-err ((lambda () 1) 2)]
|
[tc-err ((lambda () 1) 2)]
|
||||||
[tc-err (apply (lambda () 1) '(2))]
|
[tc-err (apply (lambda () 1) '(2))]
|
||||||
[tc-err ((lambda: ([x : Any] [y : Any]) 1) 2)]
|
[tc-err ((lambda: ([x : Any] [y : Any]) 1) 2)]
|
||||||
|
@ -532,33 +532,33 @@
|
||||||
[tc-err ((plambda: (a) ([x : (a -> a)] [y : a]) (x y)) 5)]
|
[tc-err ((plambda: (a) ([x : (a -> a)] [y : a]) (x y)) 5)]
|
||||||
[tc-err ((plambda: (a) ([x : a] [y : a]) x) 5)]
|
[tc-err ((plambda: (a) ([x : a] [y : a]) x) 5)]
|
||||||
[tc-err (ann 5 : String)]
|
[tc-err (ann 5 : String)]
|
||||||
|
|
||||||
;; these don't work because the type annotation gets lost in marshalling
|
;; these don't work because the type annotation gets lost in marshalling
|
||||||
#|
|
#|
|
||||||
[tc-e (letrec-syntaxes+values () ([(#{x : Number}) (values 1)]) (add1 x)) N]
|
[tc-e (letrec-syntaxes+values () ([(#{x : Number}) (values 1)]) (add1 x)) N]
|
||||||
[tc-e (letrec-values ([(#{x : Number}) (values 1)]) (add1 x)) N]
|
[tc-e (letrec-values ([(#{x : Number}) (values 1)]) (add1 x)) N]
|
||||||
[tc-e (letrec ([#{x : Number} (values 1)]) (add1 x)) N]
|
[tc-e (letrec ([#{x : Number} (values 1)]) (add1 x)) N]
|
||||||
|#
|
|#
|
||||||
|
|
||||||
[tc-e (letrec: ([x : Number (values 1)]) (add1 x)) N]
|
[tc-e (letrec: ([x : Number (values 1)]) (add1 x)) N]
|
||||||
|
|
||||||
[tc-err (let ([x (add1 5)])
|
[tc-err (let ([x (add1 5)])
|
||||||
(set! x "foo")
|
(set! x "foo")
|
||||||
x)]
|
x)]
|
||||||
;; w-c-m
|
;; w-c-m
|
||||||
[tc-e/t (with-continuation-mark 'key 'mark
|
[tc-e/t (with-continuation-mark 'key 'mark
|
||||||
3)
|
3)
|
||||||
-PosByte]
|
-PosByte]
|
||||||
[tc-err (with-continuation-mark (5 4) 1
|
[tc-err (with-continuation-mark (5 4) 1
|
||||||
3)]
|
3)]
|
||||||
[tc-err (with-continuation-mark 1 (5 4)
|
[tc-err (with-continuation-mark 1 (5 4)
|
||||||
3)]
|
3)]
|
||||||
[tc-err (with-continuation-mark 1 2 (5 4))]
|
[tc-err (with-continuation-mark 1 2 (5 4))]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; call-with-values
|
;; call-with-values
|
||||||
|
|
||||||
[tc-e (call-with-values (lambda () (values 1 2))
|
[tc-e (call-with-values (lambda () (values 1 2))
|
||||||
(lambda: ([x : Number] [y : Number]) (+ x y)))
|
(lambda: ([x : Number] [y : Number]) (+ x y)))
|
||||||
N]
|
N]
|
||||||
|
@ -567,7 +567,7 @@
|
||||||
N]
|
N]
|
||||||
[tc-err (call-with-values (lambda () 1)
|
[tc-err (call-with-values (lambda () 1)
|
||||||
(lambda: () 2))]
|
(lambda: () 2))]
|
||||||
|
|
||||||
[tc-err (call-with-values (lambda () (values 2))
|
[tc-err (call-with-values (lambda () (values 2))
|
||||||
(lambda: ([x : Number] [y : Number]) (+ x y)))]
|
(lambda: ([x : Number] [y : Number]) (+ x y)))]
|
||||||
[tc-err (call-with-values 5
|
[tc-err (call-with-values 5
|
||||||
|
@ -579,7 +579,7 @@
|
||||||
;; quote-syntax
|
;; quote-syntax
|
||||||
[tc-e/t #'3 (-Syntax -PosByte)]
|
[tc-e/t #'3 (-Syntax -PosByte)]
|
||||||
[tc-e/t #'(2 3 4) (-Syntax (-lst* -PosByte -PosByte -PosByte))]
|
[tc-e/t #'(2 3 4) (-Syntax (-lst* -PosByte -PosByte -PosByte))]
|
||||||
|
|
||||||
;; testing some primitives
|
;; testing some primitives
|
||||||
[tc-e (let ([app apply]
|
[tc-e (let ([app apply]
|
||||||
[f (lambda: [x : Number *] 3)])
|
[f (lambda: [x : Number *] 3)])
|
||||||
|
@ -587,26 +587,26 @@
|
||||||
-PosByte]
|
-PosByte]
|
||||||
[tc-e ((lambda () (call/cc (lambda: ([k : (Number -> (U))]) (if (read) 5 (k 10))))))
|
[tc-e ((lambda () (call/cc (lambda: ([k : (Number -> (U))]) (if (read) 5 (k 10))))))
|
||||||
N]
|
N]
|
||||||
|
|
||||||
[tc-e (number->string 5) -String]
|
[tc-e (number->string 5) -String]
|
||||||
|
|
||||||
[tc-e (let-values ([(a b) (quotient/remainder 5 12)]
|
[tc-e (let-values ([(a b) (quotient/remainder 5 12)]
|
||||||
[(a*) (quotient 5 12)]
|
[(a*) (quotient 5 12)]
|
||||||
[(b*) (remainder 5 12)])
|
[(b*) (remainder 5 12)])
|
||||||
(+ a b a* b*))
|
(+ a b a* b*))
|
||||||
-Nat]
|
-Nat]
|
||||||
|
|
||||||
[tc-e (raise-type-error 'foo "bar" 5) (t:Un)]
|
[tc-e (raise-type-error 'foo "bar" 5) (t:Un)]
|
||||||
[tc-e (raise-type-error 'foo "bar" 7 (list 5)) (t:Un)]
|
[tc-e (raise-type-error 'foo "bar" 7 (list 5)) (t:Un)]
|
||||||
|
|
||||||
#;[tc-e
|
#;[tc-e
|
||||||
(let ((x '(1 3 5 7 9)))
|
(let ((x '(1 3 5 7 9)))
|
||||||
(do: : Number ((x : (list-of Number) x (cdr x))
|
(do: : Number ((x : (list-of Number) x (cdr x))
|
||||||
(sum : Number 0 (+ sum (car x))))
|
(sum : Number 0 (+ sum (car x))))
|
||||||
((null? x) sum)))
|
((null? x) sum)))
|
||||||
N]
|
N]
|
||||||
|
|
||||||
|
|
||||||
;; inference with internal define
|
;; inference with internal define
|
||||||
[tc-e (let ()
|
[tc-e (let ()
|
||||||
(define x 1)
|
(define x 1)
|
||||||
|
@ -614,7 +614,7 @@
|
||||||
(define z (+ x y))
|
(define z (+ x y))
|
||||||
(* x z))
|
(* x z))
|
||||||
-PosIndex]
|
-PosIndex]
|
||||||
|
|
||||||
[tc-e/t (let ()
|
[tc-e/t (let ()
|
||||||
(define: (f [x : Number]) : Number
|
(define: (f [x : Number]) : Number
|
||||||
(define: (g [y : Number]) : Number
|
(define: (g [y : Number]) : Number
|
||||||
|
@ -623,7 +623,7 @@
|
||||||
(g 4))
|
(g 4))
|
||||||
5)
|
5)
|
||||||
-PosByte]
|
-PosByte]
|
||||||
|
|
||||||
[tc-err (let ()
|
[tc-err (let ()
|
||||||
(define x x)
|
(define x x)
|
||||||
1)]
|
1)]
|
||||||
|
@ -631,45 +631,45 @@
|
||||||
(define (x) (y))
|
(define (x) (y))
|
||||||
(define (y) (x))
|
(define (y) (x))
|
||||||
1)]
|
1)]
|
||||||
|
|
||||||
[tc-err (let ()
|
[tc-err (let ()
|
||||||
(define (x) (y))
|
(define (x) (y))
|
||||||
(define (y) 3)
|
(define (y) 3)
|
||||||
1)]
|
1)]
|
||||||
|
|
||||||
[tc-e ((case-lambda:
|
[tc-e ((case-lambda:
|
||||||
[[x : Number *] (+ 1 (car x))])
|
[[x : Number *] (+ 1 (car x))])
|
||||||
5)
|
5)
|
||||||
N]
|
N]
|
||||||
#;
|
#;
|
||||||
[tc-e `(4 ,@'(3)) (-pair N (-lst N))]
|
[tc-e `(4 ,@'(3)) (-pair N (-lst N))]
|
||||||
|
|
||||||
[tc-e
|
[tc-e
|
||||||
(let ((x '(1 3 5 7 9)))
|
(let ((x '(1 3 5 7 9)))
|
||||||
(do: : Number ((x : (Listof Number) x (cdr x))
|
(do: : Number ((x : (Listof Number) x (cdr x))
|
||||||
(sum : Number 0 (+ sum (car x))))
|
(sum : Number 0 (+ sum (car x))))
|
||||||
((null? x) sum)))
|
((null? x) sum)))
|
||||||
#:ret (ret N (-FS -top -top) (make-NoObject))]
|
#:ret (ret N (-FS -top -top) (make-NoObject))]
|
||||||
|
|
||||||
[tc-e/t (if #f 1 'foo) (-val 'foo)]
|
[tc-e/t (if #f 1 'foo) (-val 'foo)]
|
||||||
|
|
||||||
[tc-e (list* 1 2 3) (-pair -One (-pair -PosByte -PosByte))]
|
[tc-e (list* 1 2 3) (-pair -One (-pair -PosByte -PosByte))]
|
||||||
|
|
||||||
[tc-err (apply append (list 1) (list 2) (list 3) (list (list 1) "foo"))]
|
[tc-err (apply append (list 1) (list 2) (list 3) (list (list 1) "foo"))]
|
||||||
[tc-e (apply append (list 1) (list 2) (list 3) (list (list 1) (list 1))) (-lst -PosByte)]
|
[tc-e (apply append (list 1) (list 2) (list 3) (list (list 1) (list 1))) (-lst -PosByte)]
|
||||||
[tc-e (apply append (list 1) (list 2) (list 3) (list (list 1) (list "foo"))) (-lst (t:Un -String -PosByte))]
|
[tc-e (apply append (list 1) (list 2) (list 3) (list (list 1) (list "foo"))) (-lst (t:Un -String -PosByte))]
|
||||||
[tc-err (plambda: (b ...) [y : b ... b] (apply append (map list y)))]
|
[tc-err (plambda: (b ...) [y : b ... b] (apply append (map list y)))]
|
||||||
[tc-e/t (plambda: (b ...) [y : (Listof Integer) ... b] (apply append y))
|
[tc-e/t (plambda: (b ...) [y : (Listof Integer) ... b] (apply append y))
|
||||||
(-polydots (b) (->... (list) ((-lst -Integer) b) (-lst -Integer)))]
|
(-polydots (b) (->... (list) ((-lst -Integer) b) (-lst -Integer)))]
|
||||||
|
|
||||||
[tc-err (plambda: (a ...) ([z : String] . [w : Number ... a])
|
[tc-err (plambda: (a ...) ([z : String] . [w : Number ... a])
|
||||||
(apply (plambda: (b) ([x : Number] . [y : Number ... a]) x)
|
(apply (plambda: (b) ([x : Number] . [y : Number ... a]) x)
|
||||||
1 1 1 1 w))]
|
1 1 1 1 w))]
|
||||||
|
|
||||||
[tc-err (plambda: (a ...) ([z : String] . [w : Number])
|
[tc-err (plambda: (a ...) ([z : String] . [w : Number])
|
||||||
(apply (plambda: (b) ([x : Number] . [y : Number ... a]) x)
|
(apply (plambda: (b) ([x : Number] . [y : Number ... a]) x)
|
||||||
1 w))]
|
1 w))]
|
||||||
|
|
||||||
[tc-e/t (plambda: (a ...) ([z : String] . [w : Number ... a])
|
[tc-e/t (plambda: (a ...) ([z : String] . [w : Number ... a])
|
||||||
(apply (plambda: (b ...) ([x : Number] . [y : Number ... b]) x)
|
(apply (plambda: (b ...) ([x : Number] . [y : Number ... b]) x)
|
||||||
1 w))
|
1 w))
|
||||||
|
@ -685,7 +685,7 @@
|
||||||
#:object (make-Path null 0))))]
|
#:object (make-Path null 0))))]
|
||||||
[tc-e/t (inst (plambda: (a) [x : a *] (apply list x)) Integer)
|
[tc-e/t (inst (plambda: (a) [x : a *] (apply list x)) Integer)
|
||||||
((list) -Integer . ->* . (-lst -Integer))]
|
((list) -Integer . ->* . (-lst -Integer))]
|
||||||
|
|
||||||
;; instantiating dotted terms
|
;; instantiating dotted terms
|
||||||
[tc-e/t (inst (plambda: (a ...) [xs : a ... a] 3) Integer Boolean Integer)
|
[tc-e/t (inst (plambda: (a ...) [xs : a ... a] 3) Integer Boolean Integer)
|
||||||
(-Integer B -Integer . t:-> . -PosByte : -true-lfilter)]
|
(-Integer B -Integer . t:-> . -PosByte : -true-lfilter)]
|
||||||
|
@ -694,26 +694,26 @@
|
||||||
(-Integer B -Integer . t:-> . -Integer)
|
(-Integer B -Integer . t:-> . -Integer)
|
||||||
(-Integer B -Integer . t:-> . -Integer)
|
(-Integer B -Integer . t:-> . -Integer)
|
||||||
. t:-> . -PosByte : -true-filter)]
|
. t:-> . -PosByte : -true-filter)]
|
||||||
|
|
||||||
[tc-e/t (plambda: (z x y ...) () (inst map z x y ... y))
|
[tc-e/t (plambda: (z x y ...) () (inst map z x y ... y))
|
||||||
(-polydots (z x y) (t:-> (cl->*
|
(-polydots (z x y) (t:-> (cl->*
|
||||||
((t:-> x z) (-pair x (-lst x)) . t:-> . (-pair z (-lst z)))
|
((t:-> x z) (-pair x (-lst x)) . t:-> . (-pair z (-lst z)))
|
||||||
((list ((list x) (y y) . ->... . z) (-lst x)) ((-lst y) y) . ->... . (-lst z)))
|
((list ((list x) (y y) . ->... . z) (-lst x)) ((-lst y) y) . ->... . (-lst z)))
|
||||||
: (-FS (-not-filter (-val #f) #'map) (-filter (-val #f) #'map))))]
|
: (-FS (-not-filter (-val #f) #'map) (-filter (-val #f) #'map))))]
|
||||||
|
|
||||||
;; error tests
|
;; error tests
|
||||||
[tc-err (#%variable-reference number?)]
|
[tc-err (#%variable-reference number?)]
|
||||||
[tc-err (+ 3 #f)]
|
[tc-err (+ 3 #f)]
|
||||||
[tc-err (let: ([x : Number #f]) x)]
|
[tc-err (let: ([x : Number #f]) x)]
|
||||||
[tc-err (let: ([x : Number #f]) (+ 1 x))]
|
[tc-err (let: ([x : Number #f]) (+ 1 x))]
|
||||||
|
|
||||||
[tc-err
|
[tc-err
|
||||||
(let: ([x : Any '(foo)])
|
(let: ([x : Any '(foo)])
|
||||||
(if (null? x) 1
|
(if (null? x) 1
|
||||||
(if (list? x)
|
(if (list? x)
|
||||||
(add1 x)
|
(add1 x)
|
||||||
12)))]
|
12)))]
|
||||||
|
|
||||||
[tc-err (let*: ([x : Any 1]
|
[tc-err (let*: ([x : Any 1]
|
||||||
[f : (-> Void) (lambda () (set! x 'foo))])
|
[f : (-> Void) (lambda () (set! x 'foo))])
|
||||||
(if (number? x)
|
(if (number? x)
|
||||||
|
@ -724,13 +724,13 @@
|
||||||
(if (number? (not (not x)))
|
(if (number? (not (not x)))
|
||||||
(add1 x)
|
(add1 x)
|
||||||
12))]
|
12))]
|
||||||
|
|
||||||
[tc-e (filter exact-integer? (list 1 2 3 'foo))
|
[tc-e (filter exact-integer? (list 1 2 3 'foo))
|
||||||
(-lst -Integer)]
|
(-lst -Integer)]
|
||||||
|
|
||||||
[tc-e (filter even? (filter exact-integer? (list 1 2 3 'foo)))
|
[tc-e (filter even? (filter exact-integer? (list 1 2 3 'foo)))
|
||||||
(-lst -Integer)]
|
(-lst -Integer)]
|
||||||
|
|
||||||
#|
|
#|
|
||||||
[tc-err (plambda: (a ...) [as : a ... a]
|
[tc-err (plambda: (a ...) [as : a ... a]
|
||||||
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
||||||
|
@ -741,12 +741,12 @@
|
||||||
[tc-err (plambda: (a ...) [as : a ... a]
|
[tc-err (plambda: (a ...) [as : a ... a]
|
||||||
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
||||||
3 (list #\c) (map list (map list as))))]
|
3 (list #\c) (map list (map list as))))]
|
||||||
|
|
||||||
[tc-e/t (plambda: (a ...) [as : a ... a]
|
[tc-e/t (plambda: (a ...) [as : a ... a]
|
||||||
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
(apply fold-left (lambda: ([c : Integer] [a : Char] . [xs : a ... a]) c)
|
||||||
3 (list #\c) (map list as)))
|
3 (list #\c) (map list as)))
|
||||||
(-polydots (a) ((list) (a a) . ->... . -Integer))]|#
|
(-polydots (a) ((list) (a a) . ->... . -Integer))]|#
|
||||||
|
|
||||||
;; First is same as second, but with map explicitly instantiated.
|
;; First is same as second, but with map explicitly instantiated.
|
||||||
[tc-e/t (plambda: (a ...) [ys : (a ... a -> Number) *]
|
[tc-e/t (plambda: (a ...) [ys : (a ... a -> Number) *]
|
||||||
(lambda: [zs : a ... a]
|
(lambda: [zs : a ... a]
|
||||||
|
@ -761,45 +761,45 @@
|
||||||
(apply y zs))
|
(apply y zs))
|
||||||
ys)))
|
ys)))
|
||||||
(-polydots (a) ((list) ((list) (a a) . ->... . N) . ->* . ((list) (a a) . ->... . (-lst N)) : -true-lfilter))]
|
(-polydots (a) ((list) ((list) (a a) . ->... . N) . ->* . ((list) (a a) . ->... . (-lst N)) : -true-lfilter))]
|
||||||
|
|
||||||
[tc-e/t (lambda: ((x : (All (t) t)))
|
[tc-e/t (lambda: ((x : (All (t) t)))
|
||||||
((inst (inst x (All (t) (t -> t)))
|
((inst (inst x (All (t) (t -> t)))
|
||||||
(All (t) t))
|
(All (t) t))
|
||||||
x))
|
x))
|
||||||
((-poly (a) a) . t:-> . (-poly (a) a))]
|
((-poly (a) a) . t:-> . (-poly (a) a))]
|
||||||
|
|
||||||
;; We need to make sure that even if a isn't free in the dotted type, that it gets replicated
|
;; We need to make sure that even if a isn't free in the dotted type, that it gets replicated
|
||||||
;; appropriately.
|
;; appropriately.
|
||||||
[tc-e/t (inst (plambda: (a ...) [ys : Number ... a]
|
[tc-e/t (inst (plambda: (a ...) [ys : Number ... a]
|
||||||
(apply + ys))
|
(apply + ys))
|
||||||
Boolean String Number)
|
Boolean String Number)
|
||||||
(N N N . t:-> . N)]
|
(N N N . t:-> . N)]
|
||||||
|
|
||||||
[tc-e (assq 'foo #{'((a b) (foo bar)) :: (Listof (List Symbol Symbol))})
|
[tc-e (assq 'foo #{'((a b) (foo bar)) :: (Listof (List Symbol Symbol))})
|
||||||
(t:Un (-val #f) (-pair Sym (-pair Sym (-val null))))]
|
(t:Un (-val #f) (-pair Sym (-pair Sym (-val null))))]
|
||||||
|
|
||||||
[tc-e/t (ann (lambda (x) x) (All (a) (a -> a)))
|
[tc-e/t (ann (lambda (x) x) (All (a) (a -> a)))
|
||||||
(-poly (a) (a . t:-> . a))]
|
(-poly (a) (a . t:-> . a))]
|
||||||
[tc-e (apply values (list 1 2 3)) #:ret (ret (list -One -PosByte -PosByte))]
|
[tc-e (apply values (list 1 2 3)) #:ret (ret (list -One -PosByte -PosByte))]
|
||||||
|
|
||||||
[tc-e/t (ann (if #t 3 "foo") Integer) -Integer]
|
[tc-e/t (ann (if #t 3 "foo") Integer) -Integer]
|
||||||
|
|
||||||
[tc-e/t (plambda: (a ...) ([x : Number] . [y : a ... a])
|
[tc-e/t (plambda: (a ...) ([x : Number] . [y : a ... a])
|
||||||
(andmap null? (map list y)))
|
(andmap null? (map list y)))
|
||||||
(-polydots (a) ((list -Number) (a a) . ->... . -Boolean))]
|
(-polydots (a) ((list -Number) (a a) . ->... . -Boolean))]
|
||||||
[tc-e (ann (error 'foo) (values Number Number)) #:ret (ret (list -Number -Number))]
|
[tc-e (ann (error 'foo) (values Number Number)) #:ret (ret (list -Number -Number))]
|
||||||
|
|
||||||
[tc-e (string->number "123")
|
[tc-e (string->number "123")
|
||||||
(t:Un (-val #f) -Number)]
|
(t:Un (-val #f) -Number)]
|
||||||
|
|
||||||
[tc-e #{(make-hash) :: (HashTable Number Number)}
|
[tc-e #{(make-hash) :: (HashTable Number Number)}
|
||||||
(make-Hashtable -Number -Number)]
|
(make-Hashtable -Number -Number)]
|
||||||
#;[tc-err (let: ([fact : (Number -> Number) (lambda: ([n : Number]) (if (zero? n) 1 (* n (fact (- n 1)))))])
|
#;[tc-err (let: ([fact : (Number -> Number) (lambda: ([n : Number]) (if (zero? n) 1 (* n (fact (- n 1)))))])
|
||||||
(fact 20))]
|
(fact 20))]
|
||||||
|
|
||||||
[tc-err (ann (lambda: ([x : Any]) #f) (Any -> Boolean : String))]
|
[tc-err (ann (lambda: ([x : Any]) #f) (Any -> Boolean : String))]
|
||||||
|
|
||||||
|
|
||||||
[tc-e (time (+ 3 4)) -PosIndex]
|
[tc-e (time (+ 3 4)) -PosIndex]
|
||||||
|
|
||||||
|
|
||||||
|
@ -809,7 +809,7 @@
|
||||||
(lambda: ([v : (Listof Number)]
|
(lambda: ([v : (Listof Number)]
|
||||||
[cpu : Number]
|
[cpu : Number]
|
||||||
[user : Number]
|
[user : Number]
|
||||||
[gc : Number])
|
[gc : Number])
|
||||||
'whatever))
|
'whatever))
|
||||||
#:ret (ret (-val 'whatever) -true-filter)]
|
#:ret (ret (-val 'whatever) -true-filter)]
|
||||||
[tc-e (let: ([l : (Listof Any) (list 1 2 3)])
|
[tc-e (let: ([l : (Listof Any) (list 1 2 3)])
|
||||||
|
@ -817,9 +817,9 @@
|
||||||
(+ 1 (car l))
|
(+ 1 (car l))
|
||||||
7))
|
7))
|
||||||
-Number]
|
-Number]
|
||||||
(tc-e (or (string->number "7") 7)
|
(tc-e (or (string->number "7") 7)
|
||||||
#:ret (ret -Number -true-filter))
|
#:ret (ret -Number -true-filter))
|
||||||
[tc-e (let ([x 1]) (if x x (add1 x)))
|
[tc-e (let ([x 1]) (if x x (add1 x)))
|
||||||
#:ret (ret -One (-FS -top -top))]
|
#:ret (ret -One (-FS -top -top))]
|
||||||
[tc-e (let: ([x : (U (Vectorof Number) String) (vector 1 2 3)])
|
[tc-e (let: ([x : (U (Vectorof Number) String) (vector 1 2 3)])
|
||||||
(if (vector? x) (vector-ref x 0) (string-length x)))
|
(if (vector? x) (vector-ref x 0) (string-length x)))
|
||||||
|
@ -831,7 +831,7 @@
|
||||||
[tc-e (let ()
|
[tc-e (let ()
|
||||||
(define: x : Any 7)
|
(define: x : Any 7)
|
||||||
(if (box? x) (unbox x) (+ 1)))
|
(if (box? x) (unbox x) (+ 1)))
|
||||||
Univ]
|
Univ]
|
||||||
[tc-e (floor 1/2) -Nat]
|
[tc-e (floor 1/2) -Nat]
|
||||||
[tc-e (ceiling 1/2) -PosInt]
|
[tc-e (ceiling 1/2) -PosInt]
|
||||||
[tc-e (truncate 0.5) -NonNegFlonum]
|
[tc-e (truncate 0.5) -NonNegFlonum]
|
||||||
|
@ -864,7 +864,7 @@
|
||||||
[tc-e ((inst map Number (Pairof Number Number)) car (ann (list (cons 1 2) (cons 2 3) (cons 4 5)) (Listof (Pairof Number Number))))
|
[tc-e ((inst map Number (Pairof Number Number)) car (ann (list (cons 1 2) (cons 2 3) (cons 4 5)) (Listof (Pairof Number Number))))
|
||||||
(-lst -Number)]
|
(-lst -Number)]
|
||||||
[tc-err (list (values 1 2))]
|
[tc-err (list (values 1 2))]
|
||||||
|
|
||||||
#| ;; should work but don't (test harness problems)
|
#| ;; should work but don't (test harness problems)
|
||||||
[tc-e (for/list ([(k v) (in-hash #hash((1 . 2)))]) 0) (-lst -Zero)]
|
[tc-e (for/list ([(k v) (in-hash #hash((1 . 2)))]) 0) (-lst -Zero)]
|
||||||
[tc-e (in-list (list 1 2 3)) (-seq -Integer)]
|
[tc-e (in-list (list 1 2 3)) (-seq -Integer)]
|
||||||
|
@ -968,7 +968,7 @@
|
||||||
(tc-e (not #f) #:ret (ret B (-FS -top -bot)))
|
(tc-e (not #f) #:ret (ret B (-FS -top -bot)))
|
||||||
(tc-e (false? #f) #:ret (ret B (-FS -top -bot)))
|
(tc-e (false? #f) #:ret (ret B (-FS -top -bot)))
|
||||||
(tc-e (not #t) #:ret (ret B (-FS -bot -top)))
|
(tc-e (not #t) #:ret (ret B (-FS -bot -top)))
|
||||||
;; It's not clear why the following test doesn't work,
|
;; It's not clear why the following test doesn't work,
|
||||||
;; but it works fine in the real typechecker
|
;; but it works fine in the real typechecker
|
||||||
;(tc-e (false? #t) #:ret (ret B (-FS -bot -top)))
|
;(tc-e (false? #t) #:ret (ret B (-FS -bot -top)))
|
||||||
|
|
||||||
|
@ -1051,7 +1051,7 @@
|
||||||
(tc-e (find-system-path 'home-dir) -Path)
|
(tc-e (find-system-path 'home-dir) -Path)
|
||||||
(tc-e (path-list-string->path-list "/bin:/sbin:/usr/bin" null) (-lst -Path))
|
(tc-e (path-list-string->path-list "/bin:/sbin:/usr/bin" null) (-lst -Path))
|
||||||
(tc-e (find-executable-path "racket" "collects" #t) (-opt -Path))
|
(tc-e (find-executable-path "racket" "collects" #t) (-opt -Path))
|
||||||
|
|
||||||
(tc-e (file-exists? "/usr") B)
|
(tc-e (file-exists? "/usr") B)
|
||||||
(tc-e (link-exists? "/usr") B)
|
(tc-e (link-exists? "/usr") B)
|
||||||
(tc-e (delete-file "does-not-exist") -Void)
|
(tc-e (delete-file "does-not-exist") -Void)
|
||||||
|
@ -1158,7 +1158,7 @@
|
||||||
(tc-e (make-handle-get-preference-locked .3 'sym (lambda () 'eseh) 'timestamp #f #:lock-there #f #:max-delay .45)
|
(tc-e (make-handle-get-preference-locked .3 'sym (lambda () 'eseh) 'timestamp #f #:lock-there #f #:max-delay .45)
|
||||||
(t:-> -Pathlike ManyUniv))
|
(t:-> -Pathlike ManyUniv))
|
||||||
|
|
||||||
(tc-e (call-with-file-lock/timeout #f 'exclusive (lambda () 'res) (lambda () 'err)
|
(tc-e (call-with-file-lock/timeout #f 'exclusive (lambda () 'res) (lambda () 'err)
|
||||||
#:get-lock-file (lambda () "lock")
|
#:get-lock-file (lambda () "lock")
|
||||||
#:delay .01
|
#:delay .01
|
||||||
#:max-delay .2) (one-of/c 'res 'err))
|
#:max-delay .2) (one-of/c 'res 'err))
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; "bug" found - handling of empty heaps
|
;; "bug" found - handling of empty heaps
|
||||||
(pdefine: (a) (find-min [pq : (priority-queue a)]) : a
|
(pdefine: (a) (find-min [pq : (priority-queue a)]) : a
|
||||||
(let ([h (heap pq)])
|
(let ([h (heap pq)])
|
||||||
(if (heap:heap-node? h)
|
(if (heap:heap-node? h)
|
||||||
(elm (heap:find-min h))
|
(elm (heap:find-min h))
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
[-StrRx (Un -String -Regexp)]
|
[-StrRx (Un -String -Regexp)]
|
||||||
[-BtsRx (Un -Bytes -Byte-Regexp)])
|
[-BtsRx (Un -Bytes -Byte-Regexp)])
|
||||||
((Un -BtsRx -StrRx) -Input-Port [N ?N ?outp -Bytes] . ->opt . (optlist -Bytes)))]
|
((Un -BtsRx -StrRx) -Input-Port [N ?N ?outp -Bytes] . ->opt . (optlist -Bytes)))]
|
||||||
|
|
||||||
|
|
||||||
[regexp-match-positions
|
[regexp-match-positions
|
||||||
(let* ([?outp (-opt -Output-Port)]
|
(let* ([?outp (-opt -Output-Port)]
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
[N index-type]
|
[N index-type]
|
||||||
[?N (-opt index-type)]
|
[?N (-opt index-type)]
|
||||||
[ind-pair (-pair -Index -Index)]
|
[ind-pair (-pair -Index -Index)]
|
||||||
[output (-lst ind-pair)]
|
[output (-lst ind-pair)]
|
||||||
[-Input (Un -String -Input-Port -Bytes -Path)])
|
[-Input (Un -String -Input-Port -Bytes -Path)])
|
||||||
(->opt -Pattern -Input [N ?N ?outp -Bytes] output))]
|
(->opt -Pattern -Input [N ?N ?outp -Bytes] output))]
|
||||||
|
|
||||||
|
|
|
@ -1838,8 +1838,8 @@
|
||||||
[unsafe-flmin flmin-type]
|
[unsafe-flmin flmin-type]
|
||||||
[unsafe-flmax flmax-type]
|
[unsafe-flmax flmax-type]
|
||||||
|
|
||||||
;These are currently the same binding as the safe versions
|
;These are currently the same binding as the safe versions
|
||||||
;and so are not needed. If this changes they should be
|
;and so are not needed. If this changes they should be
|
||||||
;uncommented. There is a check in the definitions part of
|
;uncommented. There is a check in the definitions part of
|
||||||
;the file that makes sure that they are the same binding.
|
;the file that makes sure that they are the same binding.
|
||||||
;
|
;
|
||||||
|
|
|
@ -446,7 +446,7 @@
|
||||||
;thread-suspend-evt
|
;thread-suspend-evt
|
||||||
|
|
||||||
;Section 10.1.4
|
;Section 10.1.4
|
||||||
[thread-send (-poly (a)
|
[thread-send (-poly (a)
|
||||||
(cl->*
|
(cl->*
|
||||||
(-> -Thread Univ -Void)
|
(-> -Thread Univ -Void)
|
||||||
(-> -Thread Univ (-val #f) (-opt -Void))
|
(-> -Thread Univ (-val #f) (-opt -Void))
|
||||||
|
@ -575,7 +575,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; Section 3.7
|
;; Section 3.7
|
||||||
;; Regular Expressions
|
;; Regular Expressions
|
||||||
|
|
||||||
[regexp? (make-pred-ty -Regexp)]
|
[regexp? (make-pred-ty -Regexp)]
|
||||||
[pregexp? (make-pred-ty -PRegexp)]
|
[pregexp? (make-pred-ty -PRegexp)]
|
||||||
|
@ -2128,7 +2128,7 @@
|
||||||
|
|
||||||
[open-input-string (-> -String -Input-Port)]
|
[open-input-string (-> -String -Input-Port)]
|
||||||
[open-input-bytes (-> -Bytes -Input-Port)]
|
[open-input-bytes (-> -Bytes -Input-Port)]
|
||||||
[open-output-string
|
[open-output-string
|
||||||
([Univ] . ->opt . -Output-Port)]
|
([Univ] . ->opt . -Output-Port)]
|
||||||
[open-output-bytes
|
[open-output-bytes
|
||||||
([Univ] . ->opt . -Output-Port)]
|
([Univ] . ->opt . -Output-Port)]
|
||||||
|
@ -2215,9 +2215,9 @@
|
||||||
[open-output-nowhere (-> -Output-Port)]
|
[open-output-nowhere (-> -Output-Port)]
|
||||||
[peeking-input-port (->opt -Input-Port [Univ -Nat] -Input-Port)]
|
[peeking-input-port (->opt -Input-Port [Univ -Nat] -Input-Port)]
|
||||||
|
|
||||||
[reencode-input-port
|
[reencode-input-port
|
||||||
(->opt -Input-Port -String (-opt -Bytes) [Univ Univ Univ (-> -String -Input-Port ManyUniv)] -Input-Port)]
|
(->opt -Input-Port -String (-opt -Bytes) [Univ Univ Univ (-> -String -Input-Port ManyUniv)] -Input-Port)]
|
||||||
[reencode-output-port
|
[reencode-output-port
|
||||||
(->opt -Output-Port -String (-opt -Bytes) [Univ Univ (-opt -Bytes) (-> -String -Output-Port ManyUniv)] -Output-Port)]
|
(->opt -Output-Port -String (-opt -Bytes) [Univ Univ (-opt -Bytes) (-> -String -Output-Port ManyUniv)] -Output-Port)]
|
||||||
|
|
||||||
[dup-input-port (-Input-Port (B) . ->opt . -Input-Port)]
|
[dup-input-port (-Input-Port (B) . ->opt . -Input-Port)]
|
||||||
|
@ -2449,7 +2449,7 @@
|
||||||
|
|
||||||
;12.9.1
|
;12.9.1
|
||||||
[readtable? (make-pred-ty -Read-Table)]
|
[readtable? (make-pred-ty -Read-Table)]
|
||||||
[make-readtable
|
[make-readtable
|
||||||
(cl->*
|
(cl->*
|
||||||
(-> -Read-Table -Read-Table)
|
(-> -Read-Table -Read-Table)
|
||||||
(-> -Read-Table
|
(-> -Read-Table
|
||||||
|
@ -2469,14 +2469,14 @@
|
||||||
(Un -Char (one-of/c 'terminating-macro 'non-terminating-macro))
|
(Un -Char (one-of/c 'terminating-macro 'non-terminating-macro))
|
||||||
(-opt (Un (-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
(-opt (Un (-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
||||||
(-opt -PosInt) (-opt -Nat) Univ)
|
(-opt -PosInt) (-opt -Nat) Univ)
|
||||||
(cl->*
|
(cl->*
|
||||||
|
|
||||||
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
||||||
(-opt -PosInt) (-opt -Nat) Univ)
|
(-opt -PosInt) (-opt -Nat) Univ)
|
||||||
(-> -Char -Input-Port Univ))))
|
(-> -Char -Input-Port Univ))))
|
||||||
(-opt (Un (-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
(-opt (Un (-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
||||||
(-opt -PosInt) (-opt -Nat) Univ)
|
(-opt -PosInt) (-opt -Nat) Univ)
|
||||||
(cl->*
|
(cl->*
|
||||||
|
|
||||||
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
(-> -Char -Input-Port (-opt -PosInt) (-opt -Nat)
|
||||||
(-opt -PosInt) (-opt -Nat) Univ)
|
(-opt -PosInt) (-opt -Nat) Univ)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
@title[#:tag "beginning"]{Beginning Typed Racket}
|
@title[#:tag "beginning"]{Beginning Typed Racket}
|
||||||
|
|
||||||
Recall the typed module from @secref["quick"]:
|
Recall the typed module from @secref["quick"]:
|
||||||
|
|
||||||
@|typed-mod|
|
@|typed-mod|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ This specifies that the module is written in the
|
||||||
@racketmodname[racket] language. Typed versions of other languages
|
@racketmodname[racket] language. Typed versions of other languages
|
||||||
are provided as well; for example, the
|
are provided as well; for example, the
|
||||||
@racketmodname[typed/racket/base] language corresponds to
|
@racketmodname[typed/racket/base] language corresponds to
|
||||||
@racketmodname[racket/base].
|
@racketmodname[racket/base].
|
||||||
|
|
||||||
@racketblock[(struct: pt ([x : Real] [y : Real]))]
|
@racketblock[(struct: pt ([x : Real] [y : Real]))]
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ In order to calculate interesting facts about trees, we have to take
|
||||||
them apart and get at their contents. But since accessors such as
|
them apart and get at their contents. But since accessors such as
|
||||||
@racket[node-left] require a @racket[node] as input, not a
|
@racket[node-left] require a @racket[node] as input, not a
|
||||||
@racket[Tree], we have to determine which kind of input we
|
@racket[Tree], we have to determine which kind of input we
|
||||||
were passed.
|
were passed.
|
||||||
|
|
||||||
For this purpose, we use the predicates that come with each defined
|
For this purpose, we use the predicates that come with each defined
|
||||||
structure. For example, the @racket[leaf?] predicate distinguishes
|
structure. For example, the @racket[leaf?] predicate distinguishes
|
||||||
|
@ -117,7 +117,7 @@ process of elimination we can determine that @racket[t] must be a
|
||||||
@section{Type Errors}
|
@section{Type Errors}
|
||||||
|
|
||||||
When Typed Racket detects a type error in the module, it raises an
|
When Typed Racket detects a type error in the module, it raises an
|
||||||
error before running the program.
|
error before running the program.
|
||||||
|
|
||||||
@examples[#:eval the-eval
|
@examples[#:eval the-eval
|
||||||
(add1 "not a number")
|
(add1 "not a number")
|
||||||
|
|
|
@ -49,7 +49,7 @@ in both top-level and internal contexts.
|
||||||
|
|
||||||
Here, @racket[x] has the type @racket[Number], and @racket[id] has the
|
Here, @racket[x] has the type @racket[Number], and @racket[id] has the
|
||||||
type @racket[(Number -> Number)]. In the body of @racket[id],
|
type @racket[(Number -> Number)]. In the body of @racket[id],
|
||||||
@racket[z] has the type @racket[Number].
|
@racket[z] has the type @racket[Number].
|
||||||
|
|
||||||
@subsection{Annotating Local Binding}
|
@subsection{Annotating Local Binding}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ The @racket[let*-values:] and @racket[letrec-values:] forms are similar.
|
||||||
|
|
||||||
Function expressions also bind variables, which can be annotated with
|
Function expressions also bind variables, which can be annotated with
|
||||||
types. This function expects two arguments, a @racket[Number] and a
|
types. This function expects two arguments, a @racket[Number] and a
|
||||||
@racket[String]:
|
@racket[String]:
|
||||||
|
|
||||||
@racketblock[(lambda: ([x : Number] [y : String]) (+ x 5))]
|
@racketblock[(lambda: ([x : Number] [y : String]) (+ x 5))]
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ Functions defined by cases may also be annotated:
|
||||||
@racketblock[(case-lambda: [() 0]
|
@racketblock[(case-lambda: [() 0]
|
||||||
[([x : Number]) x])]
|
[([x : Number]) x])]
|
||||||
|
|
||||||
This function has the type
|
This function has the type
|
||||||
@racket[(case-lambda (-> Number) (Number -> Number))].
|
@racket[(case-lambda (-> Number) (Number -> Number))].
|
||||||
|
|
||||||
@subsection{Annotating Single Variables}
|
@subsection{Annotating Single Variables}
|
||||||
|
|
||||||
|
@ -107,13 +107,13 @@ especially useful for binding forms which do not have counterparts
|
||||||
provided by Typed Racket, such as @racket[let+]:
|
provided by Typed Racket, such as @racket[let+]:
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(let+ ([val #,(annvar x Number) (+ 6 1)])
|
(let+ ([val #,(annvar x Number) (+ 6 1)])
|
||||||
(* x x))]
|
(* x x))]
|
||||||
|
|
||||||
@subsection{Annotating Expressions}
|
@subsection{Annotating Expressions}
|
||||||
|
|
||||||
It is also possible to provide an expected type for a particular
|
It is also possible to provide an expected type for a particular
|
||||||
expression.
|
expression.
|
||||||
|
|
||||||
@racketblock[(ann (+ 7 1) Number)]
|
@racketblock[(ann (+ 7 1) Number)]
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ infer them. For example, the types of all local bindings using
|
||||||
@racketblock[(let ([x 7]) (add1 x))]
|
@racketblock[(let ([x 7]) (add1 x))]
|
||||||
|
|
||||||
In this example, @racket[x] has the type
|
In this example, @racket[x] has the type
|
||||||
@racket[Exact-Positive-Integer].
|
@racket[Exact-Positive-Integer].
|
||||||
|
|
||||||
Similarly, top-level constant definitions do not require annotation:
|
Similarly, top-level constant definitions do not require annotation:
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ Similarly, top-level constant definitions do not require annotation:
|
||||||
In this examples, @racket[y] has the type @racket[String].
|
In this examples, @racket[y] has the type @racket[String].
|
||||||
|
|
||||||
Finally, the parameter types for loops are inferred from their initial
|
Finally, the parameter types for loops are inferred from their initial
|
||||||
values.
|
values.
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(let loop ([x 0] [y (list 1 2 3)])
|
(let loop ([x 0] [y (list 1 2 3)])
|
||||||
|
@ -154,7 +154,7 @@ variable has type @racket[(Integer (Listof Integer) -> Integer)].
|
||||||
|
|
||||||
@section{New Type Names}
|
@section{New Type Names}
|
||||||
|
|
||||||
Any type can be given a name with @racket[define-type].
|
Any type can be given a name with @racket[define-type].
|
||||||
|
|
||||||
@racketblock[(define-type NN (Number -> Number))]
|
@racketblock[(define-type NN (Number -> Number))]
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
Given a module written in the @racketmodname[racket] language, using
|
Given a module written in the @racketmodname[racket] language, using
|
||||||
Typed Racket requires the following steps:
|
Typed Racket requires the following steps:
|
||||||
|
|
||||||
@itemize[#:style
|
@itemize[#:style
|
||||||
'ordered
|
'ordered
|
||||||
@item{Change the language to @racketmodname[typed/racket].}
|
@item{Change the language to @racketmodname[typed/racket].}
|
||||||
@item{Change the uses of @racket[(require mod)] to
|
@item{Change the uses of @racket[(require mod)] to
|
||||||
@racket[(require typed/mod)].}
|
@racket[(require typed/mod)].}
|
||||||
@item{Annotate structure definitions and top-level
|
@item{Annotate structure definitions and top-level
|
||||||
definitions with their types.} ]
|
definitions with their types.} ]
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
@title[#:tag "types"]{Types in Typed Racket}
|
@title[#:tag "types"]{Types in Typed Racket}
|
||||||
|
|
||||||
Typed Racket provides a rich variety of types to describe data. This
|
Typed Racket provides a rich variety of types to describe data. This
|
||||||
section introduces them.
|
section introduces them.
|
||||||
|
|
||||||
@section{Basic Types}
|
@section{Basic Types}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ each of these types.
|
||||||
@section{Union Types}
|
@section{Union Types}
|
||||||
|
|
||||||
Sometimes a value can be one of several types. To specify this, we
|
Sometimes a value can be one of several types. To specify this, we
|
||||||
can use a union type, written with the type constructor @racket[U].
|
can use a union type, written with the type constructor @racket[U].
|
||||||
|
|
||||||
@interaction[#:eval the-eval
|
@interaction[#:eval the-eval
|
||||||
(let ([a-number 37])
|
(let ([a-number 37])
|
||||||
|
@ -83,7 +83,7 @@ can use a union type, written with the type constructor @racket[U].
|
||||||
'no))]
|
'no))]
|
||||||
|
|
||||||
Any number of types can be combined together in a union, and nested
|
Any number of types can be combined together in a union, and nested
|
||||||
unions are flattened.
|
unions are flattened.
|
||||||
|
|
||||||
@racketblock[(U Number String Boolean Char)]
|
@racketblock[(U Number String Boolean Char)]
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ unions are flattened.
|
||||||
|
|
||||||
@deftech{Recursive types} can refer to themselves. This allows a type
|
@deftech{Recursive types} can refer to themselves. This allows a type
|
||||||
to describe an infinite family of data. For example, this is the type
|
to describe an infinite family of data. For example, this is the type
|
||||||
of binary trees of numbers.
|
of binary trees of numbers.
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(define-type BinaryTree (Rec BT (U Number (Pair BT BT))))]
|
(define-type BinaryTree (Rec BT (U Number (Pair BT BT))))]
|
||||||
|
@ -103,7 +103,7 @@ refers to the whole binary tree type within the body of the
|
||||||
@section{Structure Types}
|
@section{Structure Types}
|
||||||
|
|
||||||
Using @racket[struct:] introduces new types, distinct from any
|
Using @racket[struct:] introduces new types, distinct from any
|
||||||
previous type.
|
previous type.
|
||||||
|
|
||||||
@racketblock[(struct: point ([x : Real] [y : Real]))]
|
@racketblock[(struct: point ([x : Real] [y : Real]))]
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ of @racket[l], which looks like a function application. In fact, it's
|
||||||
a use of the @italic{type constructor} @racket[Listof], which takes
|
a use of the @italic{type constructor} @racket[Listof], which takes
|
||||||
another type as its input, here @racket[Number]. We can use
|
another type as its input, here @racket[Number]. We can use
|
||||||
@racket[Listof] to construct the type of any kind of list we might
|
@racket[Listof] to construct the type of any kind of list we might
|
||||||
want.
|
want.
|
||||||
|
|
||||||
We can define our own type constructors as well. For example, here is
|
We can define our own type constructors as well. For example, here is
|
||||||
an analog of the @tt{Maybe} type constructor from Haskell:
|
an analog of the @tt{Maybe} type constructor from Haskell:
|
||||||
|
@ -185,7 +185,7 @@ typed/racket
|
||||||
]
|
]
|
||||||
|
|
||||||
The first @racket[struct:] defines @racket[None] to be
|
The first @racket[struct:] defines @racket[None] to be
|
||||||
a structure with no contents.
|
a structure with no contents.
|
||||||
|
|
||||||
The second definition
|
The second definition
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ container for whatever type is supplied.
|
||||||
The @racket[find] function takes a number @racket[v] and list, and
|
The @racket[find] function takes a number @racket[v] and list, and
|
||||||
produces @racket[(Some v)] when the number is found in the list,
|
produces @racket[(Some v)] when the number is found in the list,
|
||||||
and @racket[(None)] otherwise. Therefore, it produces a
|
and @racket[(None)] otherwise. Therefore, it produces a
|
||||||
@racket[(Opt Number)], just as the annotation specified.
|
@racket[(Opt Number)], just as the annotation specified.
|
||||||
|
|
||||||
@subsection{Polymorphic Functions}
|
@subsection{Polymorphic Functions}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ corresponds to the type of the corresponding argument of @racket[f].
|
||||||
We also know that, in order to avoid arity errors, the length of
|
We also know that, in order to avoid arity errors, the length of
|
||||||
@racket[bss] must be one less than the arity of @racket[f] (as
|
@racket[bss] must be one less than the arity of @racket[f] (as
|
||||||
@racket[as] corresponds to the first argument of @racket[f]).
|
@racket[as] corresponds to the first argument of @racket[f]).
|
||||||
|
|
||||||
The example uses of @racket[map] evaluate to @racketresult[(list 2 3 4 5)],
|
The example uses of @racket[map] evaluate to @racketresult[(list 2 3 4 5)],
|
||||||
@racketresult[(list (list 1 4) (list 2 5) (list 3 6))], and
|
@racketresult[(list (list 1 4) (list 2 5) (list 3 6))], and
|
||||||
@racketresult[(list 10 14 18)].
|
@racketresult[(list 10 14 18)].
|
||||||
|
@ -73,7 +73,7 @@ In Typed Racket, we can define @racket[map] as follows:
|
||||||
|
|
||||||
@racketmod[
|
@racketmod[
|
||||||
typed/racket
|
typed/racket
|
||||||
(: map
|
(: map
|
||||||
(All (C A B ...)
|
(All (C A B ...)
|
||||||
((A B ... B -> C) (Listof A) (Listof B) ... B
|
((A B ... B -> C) (Listof A) (Listof B) ... B
|
||||||
->
|
->
|
||||||
|
|
|
@ -11,7 +11,7 @@ languages. The @racketmod[typed-scheme] language is equivalent to the
|
||||||
@racketmod[typed/scheme/base] language.
|
@racketmod[typed/scheme/base] language.
|
||||||
|
|
||||||
@(declare-exporting typed/scheme/base typed/scheme typed-scheme
|
@(declare-exporting typed/scheme/base typed/scheme typed-scheme
|
||||||
#:use-sources
|
#:use-sources
|
||||||
(typed-scheme/typed-scheme
|
(typed-scheme/typed-scheme
|
||||||
typed-scheme/base-env/prims
|
typed-scheme/base-env/prims
|
||||||
typed-scheme/base-env/extra-procs
|
typed-scheme/base-env/extra-procs
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
@title{Legacy Forms}
|
@title{Legacy Forms}
|
||||||
|
|
||||||
The following forms are provided by Typed Racket for backwards
|
The following forms are provided by Typed Racket for backwards
|
||||||
compatibility.
|
compatibility.
|
||||||
|
|
||||||
@defidform[define-type-alias]{Equivalent to @racket[define-type].}
|
@defidform[define-type-alias]{Equivalent to @racket[define-type].}
|
||||||
@defidform[define-typed-struct]{Equivalent to @racket[define-struct:]}
|
@defidform[define-typed-struct]{Equivalent to @racket[define-struct:]}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
The @racketmodname[typed/racket] language corresponds to the
|
The @racketmodname[typed/racket] language corresponds to the
|
||||||
@racketmodname[racket] language---that is, any identifier provided
|
@racketmodname[racket] language---that is, any identifier provided
|
||||||
by @racketmodname[racket], such as @racket[modulo] is available by default in
|
by @racketmodname[racket], such as @racket[modulo] is available by default in
|
||||||
@racketmodname[typed/racket].
|
@racketmodname[typed/racket].
|
||||||
|
|
||||||
@racketmod[typed/racket
|
@racketmod[typed/racket
|
||||||
(modulo 12 2)
|
(modulo 12 2)
|
||||||
|
@ -24,7 +24,7 @@ The @racketmodname[typed/racket/base] language corresponds to the
|
||||||
Some libraries have counterparts in the @racketidfont{typed}
|
Some libraries have counterparts in the @racketidfont{typed}
|
||||||
collection, which provide the same exports as the untyped versions.
|
collection, which provide the same exports as the untyped versions.
|
||||||
Such libraries include @racketmodname[srfi/14],
|
Such libraries include @racketmodname[srfi/14],
|
||||||
@racketmodname[net/url], and many others.
|
@racketmodname[net/url], and many others.
|
||||||
|
|
||||||
@racketmod[typed/racket
|
@racketmod[typed/racket
|
||||||
(require typed/srfi/14)
|
(require typed/srfi/14)
|
||||||
|
@ -32,7 +32,7 @@ Such libraries include @racketmodname[srfi/14],
|
||||||
(string->char-set "olleh"))
|
(string->char-set "olleh"))
|
||||||
]
|
]
|
||||||
|
|
||||||
To participate in making more libraries available, please visit
|
To participate in making more libraries available, please visit
|
||||||
@link["http://www.ccs.neu.edu/home/samth/adapt/"]{here}.
|
@link["http://www.ccs.neu.edu/home/samth/adapt/"]{here}.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,10 @@ result of @racket[_loop] (and thus the result of the entire
|
||||||
|
|
||||||
@ex[(: filter-even-loop : (Listof Natural) -> (Listof Natural))
|
@ex[(: filter-even-loop : (Listof Natural) -> (Listof Natural))
|
||||||
(define (filter-even-loop lst)
|
(define (filter-even-loop lst)
|
||||||
(let: loop : (Listof Natural)
|
(let: loop : (Listof Natural)
|
||||||
([accum : (Listof Natural) null]
|
([accum : (Listof Natural) null]
|
||||||
[lst : (Listof Natural) lst])
|
[lst : (Listof Natural) lst])
|
||||||
(cond
|
(cond
|
||||||
[(null? lst) accum]
|
[(null? lst) accum]
|
||||||
[(even? (car lst)) (loop (cons (car lst) accum) (cdr lst))]
|
[(even? (car lst)) (loop (cons (car lst) accum) (cdr lst))]
|
||||||
[else (loop accum (cdr lst))])))
|
[else (loop accum (cdr lst))])))
|
||||||
|
@ -84,7 +84,7 @@ Type-annotated versions of
|
||||||
@section{Anonymous Functions}
|
@section{Anonymous Functions}
|
||||||
|
|
||||||
@defform/subs[(lambda: formals . body)
|
@defform/subs[(lambda: formals . body)
|
||||||
([formals ([v : t] ...)
|
([formals ([v : t] ...)
|
||||||
([v : t] ... . [v : t *])
|
([v : t] ... . [v : t *])
|
||||||
([v : t] ... . [v : t ...])])]{
|
([v : t] ... . [v : t ...])])]{
|
||||||
A function of the formal arguments @racket[v], where each formal
|
A function of the formal arguments @racket[v], where each formal
|
||||||
|
@ -99,13 +99,13 @@ of the formal, and in any type expressions in the @racket[body].}
|
||||||
@defform[(case-lambda: [formals body] ...)]{
|
@defform[(case-lambda: [formals body] ...)]{
|
||||||
A function of multiple arities. Note that each @racket[formals] must have a
|
A function of multiple arities. Note that each @racket[formals] must have a
|
||||||
different arity.
|
different arity.
|
||||||
@ex[(define add-map
|
@ex[(define add-map
|
||||||
(case-lambda:
|
(case-lambda:
|
||||||
[([lst : (Listof Integer)])
|
[([lst : (Listof Integer)])
|
||||||
(map add1 lst)]
|
(map add1 lst)]
|
||||||
[([lst1 : (Listof Integer)]
|
[([lst1 : (Listof Integer)]
|
||||||
[lst2 : (Listof Integer)])
|
[lst2 : (Listof Integer)])
|
||||||
(map + lst1 lst2)]))]
|
(map + lst1 lst2)]))]
|
||||||
For the type declaration of @racket[add-map] look at @racket[case-lambda].}
|
For the type declaration of @racket[add-map] look at @racket[case-lambda].}
|
||||||
|
|
||||||
@defform[(pcase-lambda: (a ...) [formals body] ...)]{
|
@defform[(pcase-lambda: (a ...) [formals body] ...)]{
|
||||||
|
@ -199,7 +199,7 @@ These are identical to @|for-id| and @|for*-id|, but provide additional annotati
|
||||||
expr ...+)
|
expr ...+)
|
||||||
([step-expr-maybe code:blank
|
([step-expr-maybe code:blank
|
||||||
step-expr])]{
|
step-expr])]{
|
||||||
Like @racket[do], but each @racket[id] having the associated type @racket[t], and
|
Like @racket[do], but each @racket[id] having the associated type @racket[t], and
|
||||||
the final body @racket[expr] having the type @racket[u]. Type
|
the final body @racket[expr] having the type @racket[u]. Type
|
||||||
annotations are optional.
|
annotations are optional.
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ annotations are optional.
|
||||||
@section{Definitions}
|
@section{Definitions}
|
||||||
|
|
||||||
@defform*[[(define: v : t e)
|
@defform*[[(define: v : t e)
|
||||||
(define: (f . formals) : t . body)
|
(define: (f . formals) : t . body)
|
||||||
(define: (a ...) (f . formals) : t . body)]]{
|
(define: (a ...) (f . formals) : t . body)]]{
|
||||||
These forms define variables, with annotated types. The first form
|
These forms define variables, with annotated types. The first form
|
||||||
defines @racket[v] with type @racket[t] and value @racket[e]. The
|
defines @racket[v] with type @racket[t] and value @racket[e]. The
|
||||||
|
@ -218,12 +218,12 @@ types. In most cases, use of @racket[:] is preferred to use of @racket[define:]
|
||||||
@ex[(define: foo : Integer 10)
|
@ex[(define: foo : Integer 10)
|
||||||
|
|
||||||
(define: (add [first : Integer]
|
(define: (add [first : Integer]
|
||||||
[rest : Integer]) : Integer
|
[rest : Integer]) : Integer
|
||||||
(+ first rest))
|
(+ first rest))
|
||||||
|
|
||||||
(define: (A) (poly-app [func : (A A -> A)]
|
(define: (A) (poly-app [func : (A A -> A)]
|
||||||
[first : A]
|
[first : A]
|
||||||
[rest : A]) : A
|
[rest : A]) : A
|
||||||
(func first rest))]}
|
(func first rest))]}
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,13 +248,13 @@ Options provided have the same meaning as for the @racket[struct] form.}
|
||||||
(define-struct: maybe-type-vars name-spec ([f : t] ...) options ...)
|
(define-struct: maybe-type-vars name-spec ([f : t] ...) options ...)
|
||||||
([maybe-type-vars code:blank (v ...)]
|
([maybe-type-vars code:blank (v ...)]
|
||||||
[name-spec name (name parent)]
|
[name-spec name (name parent)]
|
||||||
[options #:transparent #:mutable])]{Legacy version of @racket[struct:],
|
[options #:transparent #:mutable])]{Legacy version of @racket[struct:],
|
||||||
corresponding to @racket[define-struct].}
|
corresponding to @racket[define-struct].}
|
||||||
|
|
||||||
@defform/subs[
|
@defform/subs[
|
||||||
(define-struct/exec: name-spec ([f : t] ...) [e : proc-t])
|
(define-struct/exec: name-spec ([f : t] ...) [e : proc-t])
|
||||||
([name-spec name (name parent)])]{
|
([name-spec name (name parent)])]{
|
||||||
Like @racket[define-struct:], but defines a procedural structure.
|
Like @racket[define-struct:], but defines a procedural structure.
|
||||||
The procdure @racket[e] is used as the value for @racket[prop:procedure], and must have type @racket[proc-t].}
|
The procdure @racket[e] is used as the value for @racket[prop:procedure], and must have type @racket[proc-t].}
|
||||||
|
|
||||||
@section{Names for Types}
|
@section{Names for Types}
|
||||||
|
@ -272,7 +272,7 @@ cycles among them are prohibited.
|
||||||
@section{Generating Predicates Automatically}
|
@section{Generating Predicates Automatically}
|
||||||
@defform[(define-predicate name t)]{
|
@defform[(define-predicate name t)]{
|
||||||
Defines @racket[name] as a predicate for the type @racket[t].
|
Defines @racket[name] as a predicate for the type @racket[t].
|
||||||
@racket[name] has the type @racket[(Any -> Boolean : t)].
|
@racket[name] has the type @racket[(Any -> Boolean : t)].
|
||||||
@racket[t] may not contain function types.}
|
@racket[t] may not contain function types.}
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,11 +300,11 @@ also be used.}
|
||||||
appropriate number of type variables. This is legal only in expression
|
appropriate number of type variables. This is legal only in expression
|
||||||
contexts.
|
contexts.
|
||||||
@ex[(foldl (inst cons Integer Integer) null (list 1 2 3 4))]
|
@ex[(foldl (inst cons Integer Integer) null (list 1 2 3 4))]
|
||||||
|
|
||||||
@ex[(: fold-list : (All (A) (Listof A) -> (Listof A)))
|
@ex[(: fold-list : (All (A) (Listof A) -> (Listof A)))
|
||||||
(define (fold-list lst)
|
(define (fold-list lst)
|
||||||
(foldl (inst cons A A) null lst))
|
(foldl (inst cons A A) null lst))
|
||||||
|
|
||||||
(fold-list (list "1" "2" "3" "4"))]
|
(fold-list (list "1" "2" "3" "4"))]
|
||||||
|
|
||||||
The syntax @litchar|{#{e @ t ...}}| may also be used.
|
The syntax @litchar|{#{e @ t ...}}| may also be used.
|
||||||
|
@ -327,7 +327,7 @@ naming a predicate, and @racket[_r] is an optionally-renamed identifier.
|
||||||
(code:line #:constructor-name constructor-id)
|
(code:line #:constructor-name constructor-id)
|
||||||
(code:line #:extra-constructor-name constructor-id)])]
|
(code:line #:extra-constructor-name constructor-id)])]
|
||||||
{This form requires identifiers from the module @racket[m], giving
|
{This form requires identifiers from the module @racket[m], giving
|
||||||
them the specified types.
|
them the specified types.
|
||||||
|
|
||||||
The first form requires @racket[r], giving it type @racket[t].
|
The first form requires @racket[r], giving it type @racket[t].
|
||||||
|
|
||||||
|
@ -343,12 +343,12 @@ Racket.
|
||||||
|
|
||||||
@ex[(module UNTYPED racket/base
|
@ex[(module UNTYPED racket/base
|
||||||
(define n 100)
|
(define n 100)
|
||||||
|
|
||||||
(struct IntTree
|
(struct IntTree
|
||||||
(elem left right))
|
(elem left right))
|
||||||
|
|
||||||
(provide n (struct-out IntTree)))
|
(provide n (struct-out IntTree)))
|
||||||
|
|
||||||
(module TYPED typed/racket
|
(module TYPED typed/racket
|
||||||
(require/typed 'UNTYPED
|
(require/typed 'UNTYPED
|
||||||
[n Natural]
|
[n Natural]
|
||||||
|
@ -360,31 +360,31 @@ Racket.
|
||||||
@index["opaque"]{The fourth case} defines a new type @racket[t]. @racket[pred], imported from
|
@index["opaque"]{The fourth case} defines a new type @racket[t]. @racket[pred], imported from
|
||||||
module @racket[m], is a predicate for this type. The type is defined
|
module @racket[m], is a predicate for this type. The type is defined
|
||||||
as precisely those values to which @racket[pred] produces
|
as precisely those values to which @racket[pred] produces
|
||||||
@racket[#t]. @racket[pred] must have type @racket[(Any -> Boolean)].
|
@racket[#t]. @racket[pred] must have type @racket[(Any -> Boolean)].
|
||||||
Opaque types must be required lexically before they are used.
|
Opaque types must be required lexically before they are used.
|
||||||
|
|
||||||
In all cases, the identifiers are protected with @rtech{contracts} which
|
In all cases, the identifiers are protected with @rtech{contracts} which
|
||||||
enforce the specified types. If this contract fails, the module
|
enforce the specified types. If this contract fails, the module
|
||||||
@racket[m] is blamed.
|
@racket[m] is blamed.
|
||||||
|
|
||||||
Some types, notably polymorphic types constructed with @racket[All],
|
Some types, notably polymorphic types constructed with @racket[All],
|
||||||
cannot be converted to contracts and raise a static error when used in
|
cannot be converted to contracts and raise a static error when used in
|
||||||
a @racket[require/typed] form. Here is an example of using
|
a @racket[require/typed] form. Here is an example of using
|
||||||
@racket[case->] in @racket[require/typed].
|
@racket[case->] in @racket[require/typed].
|
||||||
|
|
||||||
@(racketblock
|
@(racketblock
|
||||||
(require/typed racket/base
|
(require/typed racket/base
|
||||||
[file-or-directory-modify-seconds
|
[file-or-directory-modify-seconds
|
||||||
(case->
|
(case->
|
||||||
[String -> Exact-Nonnegative-Integer]
|
[String -> Exact-Nonnegative-Integer]
|
||||||
[String (Option Exact-Nonnegative-Integer)
|
[String (Option Exact-Nonnegative-Integer)
|
||||||
->
|
->
|
||||||
(U Exact-Nonnegative-Integer Void)]
|
(U Exact-Nonnegative-Integer Void)]
|
||||||
[String (Option Exact-Nonnegative-Integer) (-> Any)
|
[String (Option Exact-Nonnegative-Integer) (-> Any)
|
||||||
->
|
->
|
||||||
Any])]))
|
Any])]))
|
||||||
|
|
||||||
@racket[file-or-directory-modify-seconds] has some arguments which are optional,
|
@racket[file-or-directory-modify-seconds] has some arguments which are optional,
|
||||||
so we need to use @racket[case->].}
|
so we need to use @racket[case->].}
|
||||||
|
|
||||||
@section{Other Forms}
|
@section{Other Forms}
|
||||||
|
@ -395,7 +395,7 @@ Identical to @|with-handlers-id|, but provides additional annotations to help th
|
||||||
|
|
||||||
@defform[(#%module-begin form ...)]{
|
@defform[(#%module-begin form ...)]{
|
||||||
|
|
||||||
Legal only in a @rtech{module begin context}.
|
Legal only in a @rtech{module begin context}.
|
||||||
The @racket[#%module-begin] form of @racketmodname[typed/racket] checks all the
|
The @racket[#%module-begin] form of @racketmodname[typed/racket] checks all the
|
||||||
forms in the module, using the Typed Racket type checking rules. All
|
forms in the module, using the Typed Racket type checking rules. All
|
||||||
@racket[provide] forms are rewritten to insert contracts where appropriate.
|
@racket[provide] forms are rewritten to insert contracts where appropriate.
|
||||||
|
|
|
@ -22,13 +22,13 @@ The @racket[with-type] for allows for localized Typed Racket regions in otherwis
|
||||||
The first form, an expression, checks that @racket[body ...+] has the type @racket[type].
|
The first form, an expression, checks that @racket[body ...+] has the type @racket[type].
|
||||||
If the last expression in @racket[body ...+] returns multiple values, @racket[type] must
|
If the last expression in @racket[body ...+] returns multiple values, @racket[type] must
|
||||||
be a type of the form @racket[(values t ...)].
|
be a type of the form @racket[(values t ...)].
|
||||||
Uses of the result values are appropriately checked by contracts generated from
|
Uses of the result values are appropriately checked by contracts generated from
|
||||||
@racket[type].
|
@racket[type].
|
||||||
|
|
||||||
The second form, which can be used as a definition, checks that each of the @racket[export-id]s
|
The second form, which can be used as a definition, checks that each of the @racket[export-id]s
|
||||||
has the specified type. These types are also enforced in the surrounding code with contracts.
|
has the specified type. These types are also enforced in the surrounding code with contracts.
|
||||||
|
|
||||||
The @racket[id]s are assumed to
|
The @racket[id]s are assumed to
|
||||||
have the types ascribed to them; these types are converted to contracts and checked dynamically.
|
have the types ascribed to them; these types are converted to contracts and checked dynamically.
|
||||||
|
|
||||||
@examples[#:eval the-eval
|
@examples[#:eval the-eval
|
||||||
|
|
|
@ -21,7 +21,7 @@ any expression of this type will not evaluate to a value.}
|
||||||
|
|
||||||
@section{Base Types}
|
@section{Base Types}
|
||||||
|
|
||||||
@(define-syntax-rule
|
@(define-syntax-rule
|
||||||
(defnums (ids ...) . rest)
|
(defnums (ids ...) . rest)
|
||||||
(deftogether ((defidform ids) ...) . rest))
|
(deftogether ((defidform ids) ...) . rest))
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ The following base types are parameteric in their type arguments.
|
||||||
|
|
||||||
|
|
||||||
@defform[(Listof t)]{Homogenous @rtech{lists} of @racket[t]}
|
@defform[(Listof t)]{Homogenous @rtech{lists} of @racket[t]}
|
||||||
@defform[(List t ...)]{is the type of the list with one element, in order,
|
@defform[(List t ...)]{is the type of the list with one element, in order,
|
||||||
for each type provided to the @racket[List] type constructor.}
|
for each type provided to the @racket[List] type constructor.}
|
||||||
@defform/none[(#,(racket List) t ... trest #,(racket ...) bound)]{is the type of a list with
|
@defform/none[(#,(racket List) t ... trest #,(racket ...) bound)]{is the type of a list with
|
||||||
one element for each of the @racket[t]s, plus a sequence of elements
|
one element for each of the @racket[t]s, plus a sequence of elements
|
||||||
|
@ -238,7 +238,7 @@ corresponding to @racket[trest], where @racket[bound]
|
||||||
@ex[(box "hello world")]
|
@ex[(box "hello world")]
|
||||||
|
|
||||||
@defform[(Vectorof t)]{Homogenous @rtech{vectors} of @racket[t]}
|
@defform[(Vectorof t)]{Homogenous @rtech{vectors} of @racket[t]}
|
||||||
@defform[(Vector t ...)]{is the type of the list with one element, in order,
|
@defform[(Vector t ...)]{is the type of the list with one element, in order,
|
||||||
for each type provided to the @racket[Vector] type constructor.}
|
for each type provided to the @racket[Vector] type constructor.}
|
||||||
@defidform[FlVector]{An @rtech{flvector}.}
|
@defidform[FlVector]{An @rtech{flvector}.}
|
||||||
|
|
||||||
|
@ -262,12 +262,12 @@ corresponding to @racket[trest], where @racket[bound]
|
||||||
}
|
}
|
||||||
|
|
||||||
@defform*[[(Parameterof t)
|
@defform*[[(Parameterof t)
|
||||||
(Parameterof s t)]]{A @rtech{parameter} of @racket[t]. If two type arguments are supplied,
|
(Parameterof s t)]]{A @rtech{parameter} of @racket[t]. If two type arguments are supplied,
|
||||||
the first is the type the parameter accepts, and the second is the type returned.
|
the first is the type the parameter accepts, and the second is the type returned.
|
||||||
@ex[current-input-port
|
@ex[current-input-port
|
||||||
current-directory]
|
current-directory]
|
||||||
}
|
}
|
||||||
|
|
||||||
@defform[(Promise t)]{A @rtech{promise} of @racket[t].
|
@defform[(Promise t)]{A @rtech{promise} of @racket[t].
|
||||||
@ex[(delay 3)]}
|
@ex[(delay 3)]}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ of type @racket[Syntax-E].}
|
||||||
|
|
||||||
@defform[(Ephemeronof t)]{An @rtech{ephemeron} whose value is of type @racket[t].}
|
@defform[(Ephemeronof t)]{An @rtech{ephemeron} whose value is of type @racket[t].}
|
||||||
|
|
||||||
@section{Other Type Constructors}
|
@section{Other Type Constructors}
|
||||||
|
|
||||||
@defform*[#:id -> #:literals (* ...)
|
@defform*[#:id -> #:literals (* ...)
|
||||||
[(dom ... -> rng)
|
[(dom ... -> rng)
|
||||||
|
@ -328,10 +328,10 @@ of type @racket[Syntax-E].}
|
||||||
third form specifies a non-uniform rest argument of type
|
third form specifies a non-uniform rest argument of type
|
||||||
@racket[rest] with bound @racket[bound]. In the third form, the
|
@racket[rest] with bound @racket[bound]. In the third form, the
|
||||||
second occurrence of @racket[...] is literal, and @racket[bound]
|
second occurrence of @racket[...] is literal, and @racket[bound]
|
||||||
must be an identifier denoting a type variable. In the fourth form,
|
must be an identifier denoting a type variable. In the fourth form,
|
||||||
there must be only one @racket[dom] and @racket[pred] is the type
|
there must be only one @racket[dom] and @racket[pred] is the type
|
||||||
checked by the predicate.
|
checked by the predicate.
|
||||||
|
|
||||||
@ex[(λ: ([x : Number]) x)
|
@ex[(λ: ([x : Number]) x)
|
||||||
(λ: ([x : Number] . [y : String *]) (length y))
|
(λ: ([x : Number] . [y : String *]) (length y))
|
||||||
ormap
|
ormap
|
||||||
|
@ -373,7 +373,7 @@ name or a type variable}
|
||||||
@defform[(Rec n t)]{is a recursive type where @racket[n] is bound to the
|
@defform[(Rec n t)]{is a recursive type where @racket[n] is bound to the
|
||||||
recursive type in the body @racket[t]
|
recursive type in the body @racket[t]
|
||||||
@ex[(define-type IntList (Rec List (Pair Integer (U List Null))))
|
@ex[(define-type IntList (Rec List (Pair Integer (U List Null))))
|
||||||
|
|
||||||
(define-type (List A) (Rec List (Pair A (U List Null))))]}
|
(define-type (List A) (Rec List (Pair A (U List Null))))]}
|
||||||
|
|
||||||
@defalias[→ ->]
|
@defalias[→ ->]
|
||||||
|
|
|
@ -17,7 +17,7 @@ Typed Racket provides some additional utility functions to facilitate typed prog
|
||||||
[(assert [v A] [p? (A -> Any : B)]) B])]{
|
[(assert [v A] [p? (A -> Any : B)]) B])]{
|
||||||
Verifies that the argument satisfies the constraint. If no predicate
|
Verifies that the argument satisfies the constraint. If no predicate
|
||||||
is provided, simply checks that the value is not
|
is provided, simply checks that the value is not
|
||||||
@racket[#f].
|
@racket[#f].
|
||||||
}
|
}
|
||||||
|
|
||||||
@examples[#:eval the-top-eval
|
@examples[#:eval the-top-eval
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
Typed Racket is a family of languages, each of which enforce
|
Typed Racket is a family of languages, each of which enforce
|
||||||
that programs written in the language obey a type system that ensures
|
that programs written in the language obey a type system that ensures
|
||||||
the absence of many common errors. This guide is intended for programmers familiar
|
the absence of many common errors. This guide is intended for programmers familiar
|
||||||
with Racket. For an introduction to Racket, see the @(other-manual '(lib "scribblings/guide/guide.scrbl")).
|
with Racket. For an introduction to Racket, see the @(other-manual '(lib "scribblings/guide/guide.scrbl")).
|
||||||
|
|
||||||
@local-table-of-contents[]
|
@local-table-of-contents[]
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#lang scribble/manual
|
#lang scribble/manual
|
||||||
|
|
||||||
@title[#:tag "top"]{The Typed Racket Reference}
|
@title[#:tag "top"]{The Typed Racket Reference}
|
||||||
|
|
||||||
@author[@author+email["Sam Tobin-Hochstadt" "samth@racket-lang.org"]
|
@author[@author+email["Sam Tobin-Hochstadt" "samth@racket-lang.org"]
|
||||||
@author+email["Vincent St-Amour" "stamourv@racket-lang.org"]]
|
@author+email["Vincent St-Amour" "stamourv@racket-lang.org"]]
|
||||||
|
|
||||||
@(defmodulelang* (typed/racket/base typed/racket)
|
@(defmodulelang* (typed/racket/base typed/racket)
|
||||||
#:use-sources
|
#:use-sources
|
||||||
(typed-scheme/typed-scheme
|
(typed-scheme/typed-scheme
|
||||||
typed-scheme/base-env/prims
|
typed-scheme/base-env/prims
|
||||||
typed-scheme/base-env/extra-procs
|
typed-scheme/base-env/extra-procs
|
||||||
|
|
|
@ -409,7 +409,7 @@
|
||||||
(begin (tc-exprs (syntax->list #'es))
|
(begin (tc-exprs (syntax->list #'es))
|
||||||
(tc-expr #'e))]
|
(tc-expr #'e))]
|
||||||
;; other
|
;; other
|
||||||
[_
|
[_
|
||||||
(printf "~s\n" (continuation-mark-set->context (current-continuation-marks)))
|
(printf "~s\n" (continuation-mark-set->context (current-continuation-marks)))
|
||||||
(tc-error/expr #:return (ret (Un)) "cannot typecheck unknown form : ~a\n" (syntax->datum form))]))
|
(tc-error/expr #:return (ret (Un)) "cannot typecheck unknown form : ~a\n" (syntax->datum form))]))
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@
|
||||||
;; define-syntaxes just get noted
|
;; define-syntaxes just get noted
|
||||||
[(define-syntaxes (var:id ...) . rest)
|
[(define-syntaxes (var:id ...) . rest)
|
||||||
(map make-def-stx-binding (syntax->list #'(var ...)))]
|
(map make-def-stx-binding (syntax->list #'(var ...)))]
|
||||||
|
|
||||||
;; otherwise, do nothing in this pass
|
;; otherwise, do nothing in this pass
|
||||||
;; handles expressions, provides, requires, etc and whatnot
|
;; handles expressions, provides, requires, etc and whatnot
|
||||||
[_ (list)])))
|
[_ (list)])))
|
||||||
|
|
|
@ -131,18 +131,18 @@
|
||||||
(define -Base-Regexp (make-Base 'Base-Regexp
|
(define -Base-Regexp (make-Base 'Base-Regexp
|
||||||
#'(and/c regexp? (not/c pregexp?))
|
#'(and/c regexp? (not/c pregexp?))
|
||||||
(conjoin regexp? (negate pregexp?))
|
(conjoin regexp? (negate pregexp?))
|
||||||
#'-Regexp))
|
#'-Regexp))
|
||||||
(define -PRegexp (make-Base 'PRegexp
|
(define -PRegexp (make-Base 'PRegexp
|
||||||
#'pregexp?
|
#'pregexp?
|
||||||
pregexp?
|
pregexp?
|
||||||
#'-PRegexp))
|
#'-PRegexp))
|
||||||
(define -Regexp (*Un -PRegexp -Base-Regexp))
|
(define -Regexp (*Un -PRegexp -Base-Regexp))
|
||||||
|
|
||||||
(define -Byte-Base-Regexp (make-Base 'Byte-Regexp
|
(define -Byte-Base-Regexp (make-Base 'Byte-Regexp
|
||||||
#'(and/c byte-regexp? (not/c byte-pregexp?))
|
#'(and/c byte-regexp? (not/c byte-pregexp?))
|
||||||
(conjoin byte-regexp? (negate byte-pregexp?))
|
(conjoin byte-regexp? (negate byte-pregexp?))
|
||||||
#'-Byte-Regexp))
|
#'-Byte-Regexp))
|
||||||
(define -Byte-PRegexp (make-Base 'Byte-PRegexp #'byte-pregexp? byte-pregexp? #'-Byte-PRegexp))
|
(define -Byte-PRegexp (make-Base 'Byte-PRegexp #'byte-pregexp? byte-pregexp? #'-Byte-PRegexp))
|
||||||
(define -Byte-Regexp (*Un -Byte-Base-Regexp -Byte-PRegexp))
|
(define -Byte-Regexp (*Un -Byte-Base-Regexp -Byte-PRegexp))
|
||||||
|
|
||||||
(define -Pattern (*Un -Bytes -Regexp -Byte-Regexp -String))
|
(define -Pattern (*Un -Bytes -Regexp -Byte-Regexp -String))
|
||||||
|
@ -194,7 +194,7 @@
|
||||||
;return type of functions
|
;return type of functions
|
||||||
;FIXME
|
;FIXME
|
||||||
;This is not correct as Univ is only a single value.
|
;This is not correct as Univ is only a single value.
|
||||||
(define ManyUniv Univ)
|
(define ManyUniv Univ)
|
||||||
|
|
||||||
(define -Port (*Un -Output-Port -Input-Port))
|
(define -Port (*Un -Output-Port -Input-Port))
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(and (flonum? (imag-part x))
|
(and (flonum? (imag-part x))
|
||||||
(flonum? (real-part x)))))
|
(flonum? (real-part x)))))
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(and (number? x)
|
(and (number? x)
|
||||||
(flonum? (imag-part x))
|
(flonum? (imag-part x))
|
||||||
(flonum? (real-part x))))
|
(flonum? (real-part x))))
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
;; For simplicity, protect everything produced by Typed Racket.
|
;; For simplicity, protect everything produced by Typed Racket.
|
||||||
(define (arm stx)
|
(define (arm stx)
|
||||||
(syntax-case stx (module #%plain-module-begin
|
(syntax-case stx (module #%plain-module-begin
|
||||||
#%require #%provide begin
|
#%require #%provide begin
|
||||||
define-values define-syntaxes
|
define-values define-syntaxes
|
||||||
define-values-for-syntax)
|
define-values-for-syntax)
|
||||||
[(module name initial-import mb)
|
[(module name initial-import mb)
|
||||||
|
@ -20,6 +20,6 @@
|
||||||
(quasisyntax/loc stx (define-values ids #,(arm #'expr)))]
|
(quasisyntax/loc stx (define-values ids #,(arm #'expr)))]
|
||||||
[(define-syntaxes ids expr)
|
[(define-syntaxes ids expr)
|
||||||
(quasisyntax/loc stx (define-syntaxes ids #,(arm #'expr)))]
|
(quasisyntax/loc stx (define-syntaxes ids #,(arm #'expr)))]
|
||||||
[(define-values-for-syntax ids expr)
|
[(define-values-for-syntax ids expr)
|
||||||
(quasisyntax/loc stx (define-values-for-syntax ids #,(arm #'expr)))]
|
(quasisyntax/loc stx (define-values-for-syntax ids #,(arm #'expr)))]
|
||||||
[_ (syntax-arm stx)]))
|
[_ (syntax-arm stx)]))
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
[gif-add-comment ( GIF-Stream String -> Void )]
|
[gif-add-comment ( GIF-Stream String -> Void )]
|
||||||
[gif-end ( GIF-Stream -> Void )]
|
[gif-end ( GIF-Stream -> Void )]
|
||||||
[quantize ( String -> (values String (Listof (Vectorof Number)) (U #f (Vectorof Number))))])
|
[quantize ( String -> (values String (Listof (Vectorof Number)) (U #f (Vectorof Number))))])
|
||||||
|
|
||||||
(provide gif-stream? GIF-Stream)
|
(provide gif-stream? GIF-Stream)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#lang typed-scheme
|
#lang typed-scheme
|
||||||
|
|
||||||
(require typed/private/utils typed/mred/mred)
|
(require typed/private/utils typed/mred/mred)
|
||||||
|
|
||||||
(dt Style-List% (Class ()
|
(dt Style-List% (Class ()
|
||||||
()
|
()
|
||||||
([find-named-style
|
([find-named-style
|
||||||
(String -> (Instance (Class ()
|
(String -> (Instance (Class ()
|
||||||
()
|
()
|
||||||
([get-font (-> (Instance Font%))]))))])))
|
([get-font (-> (Instance Font%))]))))])))
|
||||||
|
|
||||||
(dt Scheme:Text% (Class ()
|
(dt Scheme:Text% (Class ()
|
||||||
|
@ -24,14 +24,14 @@
|
||||||
[get-end-position (-> Number)]
|
[get-end-position (-> Number)]
|
||||||
[insert (String Number Number -> Void)])))
|
[insert (String Number Number -> Void)])))
|
||||||
|
|
||||||
(require/typed/provide
|
(require/typed/provide
|
||||||
framework/framework
|
framework/framework
|
||||||
[preferences:set-default (Symbol Sexp (Any -> Boolean) -> Void)]
|
[preferences:set-default (Symbol Sexp (Any -> Boolean) -> Void)]
|
||||||
[preferences:set (Symbol Sexp -> Void)]
|
[preferences:set (Symbol Sexp -> Void)]
|
||||||
[editor:get-standard-style-list
|
[editor:get-standard-style-list
|
||||||
(-> (Instance Style-List%))]
|
(-> (Instance Style-List%))]
|
||||||
[scheme:text% Scheme:Text%]
|
[scheme:text% Scheme:Text%]
|
||||||
[gui-utils:ok/cancel-buttons
|
[gui-utils:ok/cancel-buttons
|
||||||
((Instance Horizontal-Panel%) ((Instance Button%) (Instance Event%) -> Void) ((Instance Button%) (Instance Event%) -> Void) -> (values Any Any))])
|
((Instance Horizontal-Panel%) ((Instance Button%) (Instance Event%) -> Void) ((Instance Button%) (Instance Event%) -> Void) -> (values Any Any))])
|
||||||
|
|
||||||
(require/typed/provide "prefs-contract.rkt"
|
(require/typed/provide "prefs-contract.rkt"
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
(require typed/private/utils)
|
(require typed/private/utils)
|
||||||
|
|
||||||
(dt Bitmap% (Class (Real Real Boolean)
|
(dt Bitmap% (Class (Real Real Boolean)
|
||||||
()
|
()
|
||||||
([get-width (-> Integer)]
|
([get-width (-> Integer)]
|
||||||
[get-height (-> Integer)])))
|
[get-height (-> Integer)])))
|
||||||
(dt Font-List% (Class () () ([find-or-create-font
|
(dt Font-List% (Class () () ([find-or-create-font
|
||||||
(case-lambda
|
(case-lambda
|
||||||
(Integer Symbol Symbol Symbol -> (Instance Font%))
|
(Integer Symbol Symbol Symbol -> (Instance Font%))
|
||||||
(Integer String Symbol Symbol Symbol -> (Instance Font%)))])))
|
(Integer String Symbol Symbol Symbol -> (Instance Font%)))])))
|
||||||
(dt Font% (Class () () ([get-face (-> (Option String))]
|
(dt Font% (Class () () ([get-face (-> (Option String))]
|
||||||
[get-point-size (-> Integer)])))
|
[get-point-size (-> Integer)])))
|
||||||
(dt Dialog% (Class ()
|
(dt Dialog% (Class ()
|
||||||
([parent Any] [width Integer] [label String])
|
([parent Any] [width Integer] [label String])
|
||||||
([show (Any -> Void)])))
|
([show (Any -> Void)])))
|
||||||
(dt Text-Field% (Class ()
|
(dt Text-Field% (Class ()
|
||||||
([parent Any] [callback Any] [label String])
|
([parent Any] [callback Any] [label String])
|
||||||
([get-value (-> String)]
|
([get-value (-> String)]
|
||||||
[focus (-> Void)])))
|
[focus (-> Void)])))
|
||||||
(dt Horizontal-Panel% (Class ()
|
(dt Horizontal-Panel% (Class ()
|
||||||
([parent Any]
|
([parent Any]
|
||||||
[stretchable-height Any #t]
|
[stretchable-height Any #t]
|
||||||
[alignment (List Symbol Symbol) #t])
|
[alignment (List Symbol Symbol) #t])
|
||||||
()))
|
()))
|
||||||
|
@ -71,12 +71,12 @@
|
||||||
(dt Button% (Class () () ()))
|
(dt Button% (Class () () ()))
|
||||||
(dt Event% (Class () () ()))
|
(dt Event% (Class () () ()))
|
||||||
|
|
||||||
(require/typed/provide
|
(require/typed/provide
|
||||||
scheme/gui
|
scheme/gui
|
||||||
[button% Button%]
|
[button% Button%]
|
||||||
[event% Event%]
|
[event% Event%]
|
||||||
[the-font-list (Instance Font-List%)]
|
[the-font-list (Instance Font-List%)]
|
||||||
[dialog% Dialog%]
|
[dialog% Dialog%]
|
||||||
[text-field% Text-Field%]
|
[text-field% Text-Field%]
|
||||||
[horizontal-panel% Horizontal-Panel%]
|
[horizontal-panel% Horizontal-Panel%]
|
||||||
[choice% Choice%]
|
[choice% Choice%]
|
||||||
|
@ -88,6 +88,6 @@
|
||||||
[bitmap% Bitmap%]
|
[bitmap% Bitmap%]
|
||||||
[color% Color%]
|
[color% Color%]
|
||||||
[snip% Snip%]
|
[snip% Snip%]
|
||||||
[open-input-text-editor
|
[open-input-text-editor
|
||||||
((Instance Text%) Integer (U 'end Integer) ((Instance Snip%) -> (Instance Snip%)) (Instance Text%) Boolean -> Input-Port)])
|
((Instance Text%) Integer (U 'end Integer) ((Instance Snip%) -> (Instance Snip%)) (Instance Text%) Boolean -> Input-Port)])
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user