utils.rkt: Replace compose-related definitions with requiring typed-compose.
This commit is contained in:
parent
a6a350ab1a
commit
a83f1b9978
1 changed files with 4 additions and 37 deletions
41
utils.rkt
41
utils.rkt
|
@ -1,13 +1,14 @@
|
|||
#lang typed/racket
|
||||
|
||||
(require (for-syntax syntax/parse racket/list))
|
||||
(require (for-syntax syntax/parse racket/list)
|
||||
typed-compose)
|
||||
|
||||
(provide Variable VariableMapping GeneralPair
|
||||
eval-with eval1-with
|
||||
extract-symbols
|
||||
any->string stringify-variable-mapping string->any map-sexp
|
||||
read-org-sexp unorg unstringify-pairs compose-n compose-3 compose-4
|
||||
multi-compose read-org-variable-mapping unorgv
|
||||
read-org-sexp unorg unstringify-pairs
|
||||
read-org-variable-mapping unorgv
|
||||
;; Syntax
|
||||
auto-hash-ref/explicit auto-hash-ref/:)
|
||||
|
||||
|
@ -129,40 +130,6 @@
|
|||
'(x y z))))
|
||||
|
||||
|
||||
;;; =========================
|
||||
;;; Composing typed functions
|
||||
;;; =========================
|
||||
|
||||
(: 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))))))
|
||||
|
||||
(define-syntax (multi-compose stx)
|
||||
;; Implementation by Sorawee Porncharoenwase.
|
||||
(syntax-parse stx
|
||||
[(_ f:expr g:expr)
|
||||
#'(compose f g)]
|
||||
[(_ f:expr funcs:expr ...)
|
||||
#'(compose f (multi-compose funcs ...))]))
|
||||
|
||||
(module+ test
|
||||
(check-equal? ((multi-compose add1
|
||||
(λ ([x : Number]) (* x 3))
|
||||
add1
|
||||
(λ ([x : Number]) (+ x 2)))
|
||||
3)
|
||||
19))
|
||||
|
||||
|
||||
;;; =========================
|
||||
;;; Org-mode interoperability
|
||||
;;; =========================
|
||||
|
|
Loading…
Reference in a new issue