Last active
March 13, 2026 20:33
-
-
Save shrynx/02adab363fdf860356ecfff1bb20511a to your computer and use it in GitHub Desktop.
Porosing new syntax extension to mezze
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ============================================================================= | |
| # Mezze - Current Style | |
| # ============================================================================= | |
| # | |
| # - Explicit module-qualified calls | |
| # - All parameters named | |
| # - Many let bindings to avoid deep nesting | |
| # - Must know module/ability names upfront | |
| # ============================================================================= | |
| ability Show 'a where { | |
| show: {value: 'a} -> String, | |
| } | |
| type User = {name: String, age: Int, email: String} | |
| impl Show User where { | |
| show = {value} -> "User($(value.name), $(value.age))", | |
| } | |
| # --- Processing: step by step with let bindings --- | |
| let formatUser: {data: String} -> String = {data} -> | |
| let trimmed = string::trim {s = data} | |
| let lower = string::toLower {s = trimmed} | |
| let parsed = json::parse {s = lower} | |
| let user = User.fromJson {json = parsed} | |
| let display = Show.show {value = user} | |
| "Found: $(display)" | |
| # --- Or deeply nested (inside-out, hard to follow) --- | |
| let formatUserNested: {data: String} -> String = {data} -> | |
| let user = User.fromJson { | |
| json = json::parse { | |
| s = string::toLower { | |
| s = string::trim {s = data} | |
| } | |
| } | |
| } | |
| "Found: $(Show.show {value = user})" | |
| let main = perform Console in | |
| let result = formatUser {data = " {\"name\": \"Alice\", \"age\": 30} "} | |
| println {msg = result} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ============================================================================= | |
| # Mezze - New Style (Proposed) | |
| # ============================================================================= | |
| # | |
| # - Method chaining: data flows left-to-right, top-to-bottom | |
| # - IDE discovery: type "value." to see available methods | |
| # - Inlay hints show type at each step of chain | |
| # - "it" is implicit receiver in impl blocks | |
| # ============================================================================= | |
| ability Show for 'a where { | |
| show: {} -> String, | |
| } | |
| type User = {name: String, age: Int, email: String} | |
| impl Show for User where { | |
| show = {} -> "User($(it.name), $(it.age))", | |
| } | |
| # Adding methods directly to User (anonymous impl) | |
| impl User where { | |
| isAdult = {} -> it.age >= 18, | |
| domain = {} -> it.email.split {sep = "@"}.last {}, | |
| } | |
| let formatUser: {data: String} -> String = {data} -> | |
| data | |
| .trim {} | |
| .toLower {} | |
| .parseJson {} | |
| .toUser {} | |
| .show {} | |
| .prepend {s = "Found: "} | |
| let main = perform Console in | |
| let result = formatUser {data = " {\"name\": \"Alice\", \"age\": 30} "} | |
| println {msg = result} | |
| # --- Processing: method chain, reads naturally --- | |
| # | |
| # IDE inlay hints: | |
| # data.trim {} : String | |
| # .toLower {} : String | |
| # .parseJson {} : Json | |
| # .toUser {} : User | |
| # .show {} : String | |
| # .prepend {...} : String | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment