Generalize type of curry to functions of arity 3+.

original commit: 088006413f3ec10dcf188b7b21668a89409f27a5
This commit is contained in:
Vincent St-Amour 2013-02-25 14:03:17 -05:00
parent 8185a65308
commit 1a4fc8a417
2 changed files with 30 additions and 3 deletions

View 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)

View File

@ -1772,9 +1772,11 @@
;; probably the most useful cases
[curry (-poly (a b c)
(cl->* ((a b . -> . c) a . -> . (b . -> . c))
((a b . -> . c) . -> . (a . -> . (b . -> . c)))))]
;; doesn't cover cases where we pass multiple of the function's arguments to curry,
;; also doesn't express that the returned function is itself curried
[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
[mcons (-poly (a b) (-> a b (-mpair a b)))]
[mcar (-poly (a b)