{ "language": "KARN", "version": "1.0.0", "description": "Token-minimal, platform-agnostic programming language built for AI agents", "repository": "https://github.com/karn-lang/karn", "license": "MIT", "tokens": { "->": { "name": "arrow", "description": "Function definition separator", "example": "add->a b: a+b" }, "!": { "name": "emit", "description": "Print or return value", "example": "! result" }, "^": { "name": "export", "description": "Public function marker", "example": "^main->:" }, "~": { "name": "mutate", "description": "Mutable bind", "example": "~count = 0" }, "?": { "name": "propagate", "description": "Unwrap Ok, propagate Err up stack", "example": "data = http.get(url)?" }, "??": { "name": "fallback", "description": "Use default value on Err", "example": "cache.get(k)??default" }, "&": { "name": "parallel", "description": "Concurrent execution, collect all results", "example": "a() & b() & c()" }, "|>": { "name": "pipe_forward", "description": "Sequential value passing between functions", "example": "auth.verify(tok) |> db.q()" }, "|~": { "name": "race", "description": "First success wins, others cancelled", "example": "primary()|~fallback()" }, "*": { "name": "map", "description": "Transform each element of collection", "example": "items*(x->x*2)" }, "%": { "name": "filter", "description": "Filter collection by predicate", "example": "items%(x->x>0)" }, "..": { "name": "range", "description": "Inclusive range", "example": "1..100" }, "@": { "name": "target", "description": "Platform declaration", "example": "@web+@ios" }, "#": { "name": "import", "description": "Stdlib module import", "example": "#http #db.pg" }, "type": { "name": "type_def", "description": "Named type declaration", "example": "type User:{id:N}" }, "match": { "name": "pattern_match", "description": "Structural pattern matching dispatch", "example": "match r{ Ok v -> v }" }, "from": { "name": "extern_import", "description": "External ecosystem import", "example": "from pip numpy as np" }, "==": { "name": "eq", "description": "Equality comparison", "example": "a == b" }, "!=": { "name": "neq", "description": "Inequality comparison", "example": "a != b" }, "<": { "name": "lt", "description": "Less than", "example": "a < b" }, "<=": { "name": "lte", "description": "Less than or equal", "example": "a <= b" }, ">": { "name": "gt", "description": "Greater than", "example": "a > b" }, ">=": { "name": "gte", "description": "Greater than or equal", "example": "a >= b" }, "Ok": { "name": "ok", "description": "Success result wrapper", "example": "Ok(42)" }, "Err": { "name": "err", "description": "Error result wrapper", "example": "Err('fail')" } }, "type_aliases": { "N": "Number (double)", "S": "String", "B": "Bool", "T": "Any (generic)" }, "ast_nodes": { "NumberLit": { "fields": ["value: number"] }, "StringLit": { "fields": ["value: string"] }, "BoolLit": { "fields": ["value: boolean"] }, "NilLit": { "fields": [] }, "Ident": { "fields": ["name: string"] }, "Bind": { "fields": ["name: string", "value: Node", "mutable: boolean"] }, "FnDef": { "fields": ["name: string|null", "params: [string, string|null][]", "ret_type: string|null", "body: Node[]", "exported: boolean"] }, "Call": { "fields": ["callee: Node", "args: Node[]", "kwargs: {string: Node}"] }, "BinOp": { "fields": ["op: string", "left: Node", "right: Node"] }, "GetAttr": { "fields": ["obj: Node", "attr: string"] }, "ListLit": { "fields": ["items: Node[]"] }, "MapLit": { "fields": ["pairs: [Node, Node][]"] }, "MatchExpr": { "fields": ["subject: Node", "arms: [Node, Node][]"] }, "Propagate": { "fields": ["expr: Node"] }, "Fallback": { "fields": ["expr: Node", "default: Node"] }, "Pipe": { "fields": ["stages: Node[]"] }, "Par": { "fields": ["exprs: Node[]"] }, "MapOp": { "fields": ["collection: Node", "fn: Node"] }, "FilterOp": { "fields": ["collection: Node", "fn: Node"] }, "RangeExpr": { "fields": ["start: Node", "end: Node"] }, "TypeDef": { "fields": ["name: string", "fields: {string: string}"] }, "Emit": { "fields": ["value: Node"] }, "StdlibImport": { "fields": ["path: string"] }, "ExternImport": { "fields": ["ecosystem: string", "package: string", "alias: string"] }, "TargetDecl": { "fields": ["targets: string[]"] } }, "stdlib": { "http": { "get": { "params": ["url: S"], "returns": "Ok(S)|Err" }, "serve": { "params": ["port: N", "routes: Map"], "returns": "Ok(nil)" }, "ws": { "params": ["url: S"], "returns": "Ok(ws)" } }, "fs": { "read": { "params": ["path: S"], "returns": "Ok(S)|Err" }, "write": { "params": ["path: S", "content: S"], "returns": "Ok(nil)|Err" }, "list": { "params": ["path: S?"], "returns": "Ok([S])|Err" } }, "log": { "info": { "params": ["msg: S"], "returns": "Ok(nil)" }, "warn": { "params": ["msg: S"], "returns": "Ok(nil)" }, "err": { "params": ["msg: S"], "returns": "Ok(nil)" } }, "env": { "get": { "params": ["key: S", "default: S?"], "returns": "Ok(S)" }, "require": { "params": ["key: S"], "returns": "Ok(S)|Err" } }, "json": { "parse": { "params": ["s: S"], "returns": "Ok(Any)|Err" }, "stringify": { "params": ["obj: Any", "indent: N?"], "returns": "Ok(S)" }, "pretty": { "params": ["obj: Any"], "returns": "Ok(S)" } }, "math": { "abs": { "params": ["x: N"], "returns": "N" }, "ceil": { "params": ["x: N"], "returns": "N" }, "floor": { "params": ["x: N"], "returns": "N" }, "round": { "params": ["x: N"], "returns": "N" }, "sqrt": { "params": ["x: N"], "returns": "N" }, "pow": { "params": ["x: N", "y: N"], "returns": "N" }, "min": { "params": ["...args: N"], "returns": "N" }, "max": { "params": ["...args: N"], "returns": "N" }, "sin": { "params": ["x: N"], "returns": "N" }, "cos": { "params": ["x: N"], "returns": "N" }, "log": { "params": ["x: N"], "returns": "N" }, "pi": { "params": [], "returns": "N" }, "e": { "params": [], "returns": "N" } }, "time": { "now": { "params": [], "returns": "N" }, "sleep": { "params": ["ms: N"], "returns": "Ok(nil)" }, "fmt": { "params": ["ts: N?", "fmt: S?"], "returns": "Ok(S)" }, "date": { "params": [], "returns": "Ok(Map)" } }, "str": { "join": { "params": ["lst: [S]", "sep: S?"], "returns": "Ok(S)" }, "split": { "params": ["s: S", "sep: S?"], "returns": "Ok([S])" }, "replace": { "params": ["s: S", "old: S", "new: S"], "returns": "Ok(S)" }, "contains": { "params": ["s: S", "sub: S"], "returns": "Ok(B)" }, "starts": { "params": ["s: S", "prefix: S"], "returns": "Ok(B)" }, "ends": { "params": ["s: S", "suffix: S"], "returns": "Ok(B)" }, "trim": { "params": ["s: S"], "returns": "Ok(S)" }, "repeat": { "params": ["s: S", "n: N"], "returns": "Ok(S)" } }, "crypto": { "md5": { "params": ["s: S"], "returns": "Ok(S)" }, "sha256": { "params": ["s: S"], "returns": "Ok(S)" }, "base64_encode": { "params": ["s: S"], "returns": "Ok(S)" }, "base64_decode": { "params": ["s: S"], "returns": "Ok(S)|Err" }, "uuid": { "params": [], "returns": "Ok(S)" } }, "db": { "q": { "params": ["table: S", "where: Map?"], "returns": "Ok([Map])" }, "exec": { "params": ["sql: S", "...args: Any"], "returns": "Ok(Map)" } } }, "builtins": { "print": { "params": ["...args: Any"], "returns": "Ok(nil)" }, "int": { "params": ["x: Any"], "returns": "N" }, "float": { "params": ["x: Any"], "returns": "N" }, "len": { "params": ["x: Any"], "returns": "N" }, "keys": { "params": ["x: Map"], "returns": "[S]" }, "values": { "params": ["x: Map"], "returns": "[Any]" }, "range": { "params": ["start: N", "end: N?"], "returns": "[N]" }, "type_of": { "params": ["x: Any"], "returns": "S" }, "repr": { "params": ["x: Any"], "returns": "S" }, "sorted": { "params": ["x: [N]"], "returns": "[N]" }, "reversed": { "params": ["x: [Any]"], "returns": "[Any]" }, "sum": { "params": ["x: [N]"], "returns": "N" }, "any": { "params": ["x: [B]"], "returns": "B" }, "all": { "params": ["x: [B]"], "returns": "B" }, "zip": { "params": ["a: [Any]", "b: [Any]"], "returns": "[(Any, Any)]" } }, "codegen_targets": { "c": { "output": ".c", "description": "C source code with full runtime", "compile": "gcc -o output input.c -lm" }, "js": { "output": ".js", "description": "JavaScript for Node.js", "run": "node output.js" }, "web": { "output": ".html", "description": "Self-contained HTML for browsers", "run": "open output.html" }, "python": { "output": ".python.py", "description": "Portable Python 3 code", "run": "python output.python.py" }, "macos-arm64": { "output": "(binary)", "description": "macOS ARM native binary", "compile": "gcc -arch arm64 -o output input.c -lm" }, "linux-x64": { "output": "(binary)", "description": "Linux x64 native binary", "compile": "gcc -m64 -o output input.c -lm" }, "linux-arm64": { "output": "(binary)", "description": "Linux ARM64 native binary", "compile": "gcc -march=armv8-a -o output input.c -lm" }, "windows-x64": { "output": "(binary)", "description": "Windows x64 PE binary", "compile": "gcc -m64 -o output.exe input.c -lm" }, "wasm32": { "output": ".wasm", "description": "WebAssembly module", "compile": "emcc input.c -o output.wasm" } }, "cli": { "run": { "usage": "karn run [--jit]", "description": "Run a .kn file (interpreted or JIT)" }, "build": { "usage": "karn build --target [-o output]", "description": "Compile to specified target" }, "check": { "usage": "karn check [file.kn ...]", "description": "Parse and type-check without running" }, "repl": { "usage": "karn repl", "description": "Start interactive REPL" } }, "examples": { "hello": { "source": "! \"Hello from KARN!\"", "tokens": 4 }, "fibonacci": { "source": "fib->n:N:N\n match n{\n 0 -> 0\n 1 -> 1\n x -> fib(x-1) + fib(x-2)\n }\n! fib(10)", "tokens": 32 }, "map_filter": { "source": "items = [1,2,3,4,5]\ndoubled = items*(x->x*2)\nevans = items%(x->x%2==0)", "tokens": 28 }, "api_server": { "source": "@web #http #db.pg\n\ntype User:{id:N, name:S, role:S}\n\n^getUser->req:\n tok = auth.verify(req.header.token)?\n user = db.q(\"users\", {id:req.p.id})?\n !user\n\nhttp.serve(3000, {\"/users/:id\": getUser})", "tokens": 47 } }, "agent_optimization": { "token_savings_vs_python": "76%", "token_savings_vs_typescript": "83%", "token_savings_vs_rust": "89%", "context_window_efficiency": "4x more code per context window vs Python", "deterministic_execution": true, "no_hidden_control_flow": true, "error_as_value": true, "multi_platform_single_source": true } }