Skip to content

Markdown standard library type #147

Description

@aallan

Markdown is the lingua franca of large language models. A typed Markdown ADT makes document structure visible to the type system, enabling contracts that verify structural properties of agent output.

Two mutually defined ADTs: MdBlock for block-level elements and MdInline for inline-level content. The two-level design makes illegal states unrepresentable at the type level (a heading cannot contain another heading).

Key advantage over Json: does not depend on Map<K,V> -- Markdown has no key-value structure, only arrays and strings. This means it could potentially be implemented before Json.

Parse/render functions (md_parse, md_render) are pure. Accessor functions (md_has_heading, md_has_code_block, md_extract_code_blocks) enable contracts on Markdown structure. Document conversion (PDF, Word, HTML to Markdown) uses IO effect + host bindings to external tools like MarkItDown.

Refinement type examples:

type HasTitle = { @MdBlock | md_has_heading(@MdBlock.0, 1) };
type HasVeraCode = { @MdBlock | md_has_code_block(@MdBlock.0, "vera") };

Dependencies: #52 (dynamic strings), #134 (string ops), #132 (compound arrays).

Spec reference: Chapter 9, Section 9.7.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    designFuture language design (spec §0.8)enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions