{"size": 1395, "ext": "scrbl", "max_stars_repo_path": "typed-racket-datatype/scribblings/typed-racket-datatype.scrbl", "max_stars_repo_name": "AlexKnauth/typed-racket-datatype", "max_stars_repo_stars_event_min_datetime": "2020-05-01T13:32:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-01T13:32:08.000Z", "max_issues_repo_path": "typed-racket-datatype/scribblings/typed-racket-datatype.scrbl", "max_issues_repo_name": "AlexKnauth/typed-racket-datatype", "max_issues_repo_issues_event_min_datetime": "2020-05-15T21:17:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T21:51:06.000Z", "max_forks_repo_path": "typed-racket-datatype/scribblings/typed-racket-datatype.scrbl", "max_forks_repo_name": "AlexKnauth/typed-racket-datatype", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 30.3260869565, "max_line_length": 65, "alphanum_fraction": 0.69390681}
#lang scribble/manual

@(require (for-label typed/racket/base
                     typed-racket-datatype))

@title{typed-racket-datatype}
@author{Alex Knauth}

Source code:
@url{https://github.com/AlexKnauth/typed-racket-datatype}.

@defmodule[typed-racket-datatype]{
Provides @racket[define-datatype], a form for defining
Algebraic Data Types in Typed Racket.
}

@defform[#:literals [:]
  (define-datatype header (variant-id field ...) ...)
  #:grammar [(header name-id
                     (name-id param-id ...))
             (field [field-id : field-type])]]{
Defines @racket[name-id] as an Algebraic Data Type with the
given @racket[variant-id]s defined as structs with their
respective @racket[field]s. If @racket[param-id]s are
provided, the @racket[name-id] type and the
@racket[variant-id] structs are all polymorphic with those
@racket[param-ids], otherwise they are monomorphic.

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

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