Update docs & tests for struct constructor options
This commit is contained in:
parent
796af399bf
commit
7f05dc6731
|
@ -382,7 +382,9 @@ those functions.
|
|||
(struct maybe-type-vars name-spec ([f : t] ...) options ...)
|
||||
([maybe-type-vars code:blank (v ...)]
|
||||
[name-spec name (code:line name parent)]
|
||||
[options #:transparent #:mutable #:prefab])]{
|
||||
[options #:transparent #:mutable #:prefab
|
||||
(code:line #:constructor-name constructor-id)
|
||||
(code:line #:extra-constructor-name constructor-id)])]{
|
||||
Defines a @rtech{structure} with the name @racket[name], where the
|
||||
fields @racket[f] have types @racket[t], similar to the behavior of @|struct-id|
|
||||
from @racketmodname[racket/base].
|
||||
|
|
8
typed-racket-test/fail/struct-extra-constructor.rkt
Normal file
8
typed-racket-test/fail/struct-extra-constructor.rkt
Normal file
|
@ -0,0 +1,8 @@
|
|||
#;
|
||||
(exn-pred "define-struct: expected typed structure type options")
|
||||
#lang typed/racket/base
|
||||
|
||||
(define-struct foo ()
|
||||
;; can't have both of these
|
||||
#:constructor-name foo-cn
|
||||
#:extra-constructor-name foo-ecn)
|
15
typed-racket-test/succeed/struct-options.rkt
Normal file
15
typed-racket-test/succeed/struct-options.rkt
Normal file
|
@ -0,0 +1,15 @@
|
|||
#lang typed/racket/base
|
||||
|
||||
;; Tests for constructor options for struct
|
||||
|
||||
(struct s1 ([x : Integer]) #:constructor-name cons-s1)
|
||||
(define-struct s2 ([x : Integer]) #:constructor-name cons-s2)
|
||||
(struct s3 ([x : Integer]) #:extra-constructor-name cons-s3)
|
||||
(define-struct s4 ([x : Integer]) #:extra-constructor-name cons-s4)
|
||||
|
||||
(cons-s1 1)
|
||||
(cons-s2 2)
|
||||
(s3 3)
|
||||
(cons-s3 3)
|
||||
(s4 4)
|
||||
(cons-s4 4)
|
Loading…
Reference in New Issue
Block a user