2020-12-17 21:54:12 +01:00
|
|
|
;;; typed-compose.rkt
|
|
|
|
;;;
|
|
|
|
;;; Copyright 2020 Sergiu Ivanov <sivanov@colimite.fr>
|
|
|
|
;;;
|
|
|
|
;;; This program is free software: you can redistribute it and/or
|
|
|
|
;;; modify it under the terms of the GNU General Public License as
|
|
|
|
;;; published by the Free Software Foundation, either version 3 of the
|
|
|
|
;;; License, or (at your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; This program is distributed in the hope that it will be useful,
|
|
|
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;;; General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with this program. If not, see
|
|
|
|
;;; <https://www.gnu.org/licenses/>.
|
|
|
|
|
2020-12-17 20:45:26 +01:00
|
|
|
#lang typed/racket
|
|
|
|
|
|
|
|
(require (for-syntax syntax/parse))
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(require typed/rackunit))
|
2020-12-18 11:43:17 +01:00
|
|
|
|
|
|
|
(: compose-n (All (a) (-> (-> a a) * (-> a a))))
|
|
|
|
(define (compose-n . funcs)
|
|
|
|
(λ (x)
|
|
|
|
(for/foldr ([x x]) ([f funcs])
|
|
|
|
(f x))))
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(check-equal? ((compose-n add1 add1 add1) 3) 6))
|