Hello,

I've found out that compose in Typed Racket has the type

(: compose (All (a b c) (-> (-> b c) (-> a b) (-> a c))))

which means that Typed Racket's compose can only combine two functions at a 
time.

In untyped code, I tend to use compose to combine more functions (e.g., 7), 
so I wrote myself the following definitions:

(: compose-n (All (a) (-> (-> a a) * (-> a a))))
(define (compose-n . funcs)
  (λ (x)
    (for/foldr ([x x]) ([f funcs])
      (f x))))

(: compose-3 (All (a b c d) (-> (-> c d) (-> b c) (-> a b) (-> a d))))
(define (compose-3 f1 f2 f3)
  (λ (x) (f1 (f2 (f3 x)))))

(: compose-4 (All (a b c d e) (-> (-> d e) (-> c d) (-> b c) (-> a b) (-> a 
e))))
(define (compose-4 f1 f2 f3 f4)
  (λ (x) (f1 (f2 (f3 (f4 x))))))

Is there a better way to chain compose calls in Typed Racket?

If the answer is no, is there any interest in including these three 
functions (as well as compose-5, 6, 7, 8) into Typed Racket?

-
Sergiu

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/98bb349f-5de9-4e19-bc7d-d8c2be4d8c9an%40googlegroups.com.

Reply via email to