From 4c615076589e0922fafefd8cd991d2f6a32308a5 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 11 Feb 2022 22:51:04 +0100 Subject: [PATCH] Tweaks --- src/guide/preserves.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/guide/preserves.md b/src/guide/preserves.md index 27a82ff..2b3ce54 100644 --- a/src/guide/preserves.md +++ b/src/guide/preserves.md @@ -208,12 +208,15 @@ for the type definitions above is the following: ```preserves version 1 . + BookOutline = { "sections": @sections [BookItem ...], } . + BookItem = @chapter { "Chapter": @value Chapter } / @separator "Separator" / @partTitle { "PartTitle": @value string } . + Chapter = { "name": @name string, "sub_items": @sub_items [BookItem ...], @@ -242,11 +245,13 @@ Using the TypeScript schema compiler, we see ```typescript export type BookOutline = {"sections": Array}; + export type BookItem = ( {"_variant": "chapter", "value": Chapter} | {"_variant": "separator"} | {"_variant": "partTitle", "value": string} ); + export type Chapter = {"name": string, "sub_items": Array}; ``` @@ -255,9 +260,9 @@ Using the Racket schema compiler, we see ```racket (struct BookOutline (sections)) (define (BookItem? p) - (or (BookItem-chapter? p) - (BookItem-separator? p) - (BookItem-partTitle? p))) + (or (BookItem-chapter? p) + (BookItem-separator? p) + (BookItem-partTitle? p))) (struct BookItem-chapter (value)) (struct BookItem-separator ()) (struct BookItem-partTitle (value)) @@ -281,8 +286,7 @@ BookItem = Chapter / =separator / @partTitle string . Chapter = . ``` -The schema compilers produce **exactly the same** type definitions for this variation! - +The schema compilers produce **exactly the same** type definitions for this variation. The differences are in the (de)serialization code only. Here's the Preserves value equivalent to the example above, expressed using the Preserves-native schema: