Skip to content

MON vs. YAML

YAML (YAML Ain’t Markup Language) is a human-friendly data serialization standard often used for configuration files and data exchange between languages. It emphasizes readability and a minimalist syntax. However, for complex configurations requiring robust schema validation, advanced data reusability, and a strict module system, MON (Mycel Object Notation) offers distinct advantages.

This section outlines the key differences and advantages of MON over YAML.

YAML’s readability is a core strength, using indentation to denote structure. However, its reliance on indentation can lead to subtle errors, and its flexibility can sometimes make it ambiguous.

user:
name: Alice
email: alice@example.com
settings:
theme: dark
notifications: true

MON maintains excellent readability with a more explicit, brace-delimited structure that prevents indentation-related ambiguities, while still offering features like comments and unquoted keys.

{
// Comments are first-class citizens
user: {
name: "Alice",
email: "alice@example.com",
settings: {
theme: "dark",
notifications: on, // Booleans as 'on'/'off' are natural
},
},
}

MON Advantages:

  • Explicit Structure: Braces {} and brackets [] clearly define objects and arrays, eliminating indentation-based ambiguities.
  • Comments: Explicit support for single-line // comments.
  • Unquoted Keys: Keys can be unquoted unless they contain special characters or spaces.
  • Flexible Booleans: Uses on/off in addition to true/false.

YAML has limited native support for data reusability through anchors (&) and aliases (*), but these are often shallow copies and can be complex to manage for deep structures or overrides.

default_settings: &defaults
theme: dark
notifications: true
user_alice:
name: Alice
<<: *defaults # Shallow merge
user_bob:
name: Bob
<<: *defaults
notifications: false # Overrides, but can be tricky with deep merges

MON provides a more powerful and predictable system for data reuse, with deep copying aliases and explicit spread operators for merging and overriding.

{
// Define a reusable template for default settings
&default_settings: {
theme: "dark",
notifications: on,
},
user_alice: {
name: "Alice",
// Spread the default settings (deep copy)
...*default_settings,
},
user_bob: {
name: "Bob",
// Spread the default settings and override notifications
...*default_settings,
notifications: off,
},
}

MON Advantages:

  • Deep Copy Aliases: * creates a truly independent copy, preventing unintended side effects.
  • Explicit Spreads: ...* clearly indicates merging behavior, with predictable local key precedence.
  • Reduced Ambiguity: Avoids the complexities and potential pitfalls of YAML’s merge keys.

YAML relies on external schema definitions (like JSON Schema or custom validators) to enforce data structure and types.

# my_schema.yaml (using JSON Schema syntax)
type: object
properties:
user:
type: object
properties:
name: { type: string }
email: { type: string }

MON integrates schema validation directly into the language, using #struct and #enum to define types and the :: operator for validation, ensuring data integrity at the language level.

{
User: #struct {
name(String),
email(String),
is_active(Boolean) = true,
},
alice :: User = {
id: 1,
username: "alice",
is_active: on,
},
}

MON Advantages:

  • First-Class Types: #struct and #enum are core language features, not external definitions.
  • Integrated Validation: The :: operator allows direct validation within the MON file, catching errors early.
  • Clear Error Messages: MON compiler provides precise error reporting for validation failures.

MON’s built-in type system provides a powerful yet approachable solution for schema validation, eliminating the steep learning curve and verbosity associated with YAML’s reliance on external schema definitions.

YAML typically handles multi-file configurations through external tools or pre-processors, lacking a native, standardized module system for sharing types or data.

MON offers a straightforward module system for organizing multi-file configurations and sharing types/data across files, designed for modern development workflows.

config.mon
import * as schemas from "./schemas.mon"
{
db_config :: schemas.Database = {
host: "localhost",
port: 5432,
},
}

MON Advantages:

  • Native Imports: Explicit import statements for clear dependency management.
  • Code Organization: Easily split large configurations into logical, manageable files.
  • Shared Definitions: Share types, templates, and data blocks across your project.

While YAML excels in human readability for simple data structures and configurations, MON provides a more powerful and comprehensive solution for complex and evolving projects. Its explicit syntax, advanced data reusability, integrated schema validation, and robust module system make it a superior choice for demanding configuration languages and data structuring needs.

Consider adopting MON if your project requires high maintainability, data integrity, and efficient management of complex, multi-file configurations.