Fixed the type of min and max to only operate on reals.
original commit: ef576e27c5187783648209c55d4ca211ff693e05
This commit is contained in:
parent
848b6f0e02
commit
c6a22a53f4
|
@ -30,7 +30,7 @@
|
|||
(define-typed-struct leaf ([val : Number]))
|
||||
(define-typed-struct node ([left : (Un node leaf)] [right : (Un node leaf)]))
|
||||
|
||||
(define: (tree-height [t : (Un node leaf)]) : Number
|
||||
(define: (tree-height [t : (Un node leaf)]) : Integer
|
||||
(cond [(leaf? t) 1]
|
||||
[else (max (tree-height (node-left t))
|
||||
(tree-height (node-right t)))]))
|
||||
|
@ -46,7 +46,7 @@
|
|||
|
||||
(define-type-alias tree (Un node leaf))
|
||||
|
||||
(define: (tree-height [t : tree]) : Number
|
||||
(define: (tree-height [t : tree]) : Integer
|
||||
(cond [(leaf? t) 1]
|
||||
[else (max (tree-height (node-left t))
|
||||
(tree-height (node-right t)))]))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#lang typed/scheme
|
||||
|
||||
(: x (Pair Number (Listof Number)))
|
||||
(: x (Pair Integer (Listof Integer)))
|
||||
(define x (cons 1 (list 1 2 3 4)))
|
||||
|
||||
(apply max (ann (map add1 x) : (Pair Number (Listof Number))))
|
||||
(apply max (ann (map add1 x) : (Pair Integer (Listof Integer))))
|
|
@ -93,16 +93,16 @@
|
|||
;; ----------------------------------------
|
||||
;; depth
|
||||
|
||||
(: sexp-depth (Any -> Number))
|
||||
(: sexp-depth (Any -> Integer))
|
||||
(define (sexp-depth sexp)
|
||||
(cond
|
||||
[(pair? sexp)
|
||||
(+ (max-sexp-depth sexp) 1)]
|
||||
[else 0]))
|
||||
|
||||
(: max-sexp-depth (Any -> Number))
|
||||
(: max-sexp-depth (Any -> Integer))
|
||||
(define (max-sexp-depth losx)
|
||||
(improper-foldr (λ: ([t : Any] [r : Number]) (max (sexp-depth t) r)) 0 losx))
|
||||
(improper-foldr (λ: ([t : Any] [r : Integer]) (max (sexp-depth t) r)) 0 losx))
|
||||
|
||||
(: avg-sexp-depth ((Listof Any) -> Number))
|
||||
(define (avg-sexp-depth sexps)
|
||||
|
@ -201,7 +201,7 @@
|
|||
;; ----------------------------------------
|
||||
;; expression size
|
||||
|
||||
(: atoms (Any -> Number))
|
||||
(: atoms (Any -> Integer))
|
||||
(define (atoms sexp)
|
||||
(cond
|
||||
[(null? sexp) 0]
|
||||
|
|
|
@ -120,16 +120,27 @@
|
|||
(list (->* (list -Real) -Real -Real))
|
||||
(list (->* (list N) N N))))]
|
||||
|
||||
[max (apply cl->*
|
||||
(->* (list -PositiveFixnum) -Fixnum -PositiveFixnum)
|
||||
[max (cl->* (->* (list -PositiveFixnum) -Fixnum -PositiveFixnum)
|
||||
(->* (list -NonnegativeFixnum) -Fixnum -NonnegativeFixnum)
|
||||
(->* (list -NegativeFixnum) -NegativeFixnum -NegativeFixnum)
|
||||
(->* (list -Fixnum) -Fixnum -Fixnum)
|
||||
(->* (list -Pos) -Integer -Pos)
|
||||
(->* (list -Nat) -Integer -Nat)
|
||||
(for/list ([t all-num-types]) (->* (list t) t t)))]
|
||||
[min (apply cl->*
|
||||
(->* (list -Integer) -Integer -Integer)
|
||||
(->* (list -ExactRational) -ExactRational -ExactRational)
|
||||
(->* (list -Flonum) -Flonum -Flonum)
|
||||
(->* (list -Real) -Real -Real))]
|
||||
[min (cl->* (->* (list -PositiveFixnum) -PositiveFixnum -PositiveFixnum)
|
||||
(->* (list -NonnegativeFixnum) -NonnegativeFixnum -NonnegativeFixnum)
|
||||
(->* (list -NegativeFixnum) -Fixnum -NegativeFixnum)
|
||||
(->* (list -Fixnum) -NegativeFixnum -NegativeFixnum)
|
||||
(->* (list -Fixnum) -Fixnum -Fixnum)
|
||||
(for/list ([t all-num-types]) (->* (list t) t t)))]
|
||||
(->* (list -Pos) -Pos -Pos)
|
||||
(->* (list -Nat) -Nat -Nat)
|
||||
(->* (list -Integer) -Integer -Integer)
|
||||
(->* (list -ExactRational) -ExactRational -ExactRational)
|
||||
(->* (list -Flonum) -Flonum -Flonum)
|
||||
(->* (list -Real) -Real -Real))]
|
||||
|
||||
|
||||
[add1 (cl->* (-> -Pos -Pos)
|
||||
|
|
|
@ -74,7 +74,7 @@ typed/racket
|
|||
(define-struct: leaf ([val : Number]))
|
||||
(define-struct: node ([left : Tree] [right : Tree]))
|
||||
|
||||
(: tree-height (Tree -> Number))
|
||||
(: tree-height (Tree -> Integer))
|
||||
(define (tree-height t)
|
||||
(cond [(leaf? t) 1]
|
||||
[else (max (+ 1 (tree-height (node-left t)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user