8.18
top
← prev up next →

typed-racket-datatypeπŸ”— i

Alex Knauth

Source code: https://github.com/AlexKnauth/typed-racket-datatype.

Provides define-datatype , a form for defining Algebraic Data Types in Typed Racket.

syntax

( define-datatype header(variant-idfield...)...)

header = name-id
| (name-idparam-id...)
field = [field-id: field-type]
Defines name-id as an Algebraic Data Type with the given variant-ids defined as structs with their respective fields. If param-ids are provided, the name-id type and the variant-id structs are all polymorphic with those param-ids, otherwise they are monomorphic.

Each variant struct includes a predicate and field accessors, and define-datatype also generates a predicate name-id? that accepts values that pass any of the variant predicates.

For example
(define-datatype name-id
(variant-id[field-id: field-type]... )
... )
is equivalent to
(struct variant-id([field-id: field-type]... )#:transparent)
...
(define-type name-id(U variant-id... ))
(define (name-id?x)(or (variant-id?x)... ))

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /