syndicate-2017/racket/typed/syndicate/list.rkt

40 lines
1.8 KiB
Racket
Raw Normal View History

2019-04-26 19:16:08 +00:00
#lang turnstile
(provide List
(for-syntax ~List)
list
2021-05-05 16:52:07 +00:00
(typed-out [[empty- : (List )] empty]
[[empty?- : ( (X) (→fn X (List X) Bool))] empty?]
[[cons- : ( (X) (→fn X (List X) (List X)))] cons]
[[cons?- : ( (X) (→fn X (List X) Bool))] cons?]
[[first- : ( (X) (→fn (List X) X))] first]
2019-05-17 14:34:14 +00:00
[[second- : ( (X) (→fn (List X) X))] second]
[[rest- : ( (X) (→fn (List X) (List X)))] rest]
[[member?- ( (X) (→fn X (List X) Bool))] member?]
2019-05-17 14:34:14 +00:00
[[reverse- ( (X) (→fn (List X) (List X)))] reverse]
2019-05-24 16:30:26 +00:00
[[partition- ( (X) (→fn (List X) (→fn X Bool) (List X)))] partition]
2020-10-21 15:06:15 +00:00
[[map- ( (X Y) (→fn (→fn X Y) (List X) (List Y)))] map]
[[argmax- : ( (X) (→fn (→fn X Int) (List X) X))] argmax]
2020-10-22 20:45:05 +00:00
[[argmin- : ( (X) (→fn (→fn X Int) (List X) X))] argmin]
[[remove- : ( (X) (→fn X (List X) (List X)))] remove]
[[length- : ( (X) (→fn (List X) Int))] length]))
2019-04-26 19:16:08 +00:00
(require "core-types.rkt")
2020-10-21 15:06:15 +00:00
(require (only-in "prim.rkt" Bool Int))
2019-04-26 19:16:08 +00:00
(require (postfix-in - racket/list))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lists
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-container-type List #:arity = 1)
(define-typed-syntax (list e ...)
[ e e- τ] ...
#:fail-unless (all-pure? #'(e- ...)) "expressions must be pure"
-------------------
[ (#%app- list- e- ...) (List (U τ ...))])
2019-04-26 19:16:08 +00:00
(define- (member?- v l)
(and- (#%app- member- v l) #t))