Generalize type of curry to functions of arity 3+.
This commit is contained in:
parent
3175ab2ce6
commit
088006413f
25
collects/tests/typed-racket/succeed/curry.rkt
Normal file
25
collects/tests/typed-racket/succeed/curry.rkt
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#lang typed/racket
|
||||||
|
|
||||||
|
(: f2 (Boolean Integer Integer -> Integer))
|
||||||
|
(define (f2 add? i1 i2)
|
||||||
|
(if add?
|
||||||
|
(+ i1 i2)
|
||||||
|
(- i1 i2)))
|
||||||
|
|
||||||
|
(: f3 (Boolean Integer Integer Integer -> Integer))
|
||||||
|
(define (f3 add? i1 i2 i3)
|
||||||
|
(if add?
|
||||||
|
(+ i1 i2 i3)
|
||||||
|
(- i1 i2 i3)))
|
||||||
|
|
||||||
|
(define f1a (curry f2 #t))
|
||||||
|
(define f1b (curry f3 #t))
|
||||||
|
(define f2a (curry f2))
|
||||||
|
(define f2b (curry f3))
|
||||||
|
|
||||||
|
(f2 #t 2 3)
|
||||||
|
(f2 #f 2 1)
|
||||||
|
(f1a 10 20)
|
||||||
|
(f1b 10 20 30)
|
||||||
|
((f2a #t) 10 20)
|
||||||
|
((f2b #t) 10 20 30)
|
|
@ -1772,9 +1772,11 @@
|
||||||
|
|
||||||
|
|
||||||
;; probably the most useful cases
|
;; probably the most useful cases
|
||||||
[curry (-poly (a b c)
|
;; doesn't cover cases where we pass multiple of the function's arguments to curry,
|
||||||
(cl->* ((a b . -> . c) a . -> . (b . -> . c))
|
;; also doesn't express that the returned function is itself curried
|
||||||
((a b . -> . c) . -> . (a . -> . (b . -> . c)))))]
|
[curry (-polydots (a c b)
|
||||||
|
(cl->* ((->... (list a) (b b) c) a . -> . (->... '() (b b) c))
|
||||||
|
((->... (list a) (b b) c) . -> . (a . -> . (->... '() (b b) c)))))]
|
||||||
;; mutable pairs
|
;; mutable pairs
|
||||||
[mcons (-poly (a b) (-> a b (-mpair a b)))]
|
[mcons (-poly (a b) (-> a b (-mpair a b)))]
|
||||||
[mcar (-poly (a b)
|
[mcar (-poly (a b)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user