Gren Compiler
raw JSON → 0.6.5 verified Fri May 01 auth: no javascript
Compiler for the Gren programming language, a pure functional language designed for ease of learning and powerful use. Current stable version is 0.6.5, with an active release cadence. The compiler is split into a Gren frontend and a Haskell backend, with eventual goal of full self-hosting. Differentiators: zero-install package management, task ports, 'gren run' command, and a focus on simplicity.
Common errors
error error: Could not find module 'ModuleName' ↓
cause Module not in source files or dependencies.
fix
Ensure the module is exported and imported correctly. Check package.json or gren.json for dependencies.
error Type mismatch: expected X but got Y ↓
cause Function argument type mismatch.
fix
Correct the type of the argument or modify the function signature to match.
error error: 'gren install' is not a command. See 'gren --help'. ↓
cause Using old 'gren install' command.
fix
Use 'gren package install' instead.
error fatal: Could not read from stdin. (os error 5) ↓
cause Running 'gren run' without input redirection on some platforms.
fix
Provide input via file or pipe, or run interactively with terminal.
Warnings
breaking Version 0.5.0 replaced 'gren install' with 'gren package install'. Old syntax will fail. ↓
fix Use 'gren package install' instead of 'gren install'.
gotcha The compiler is split into two parts: a Gren frontend and a Haskell backend. Building from source requires both Node.js and Haskell dependencies. ↓
fix Use the official pre-built binary or follow build instructions with devbox.
deprecated Formatter command was removed in version 0.5.0. Using 'gren format' will error. ↓
fix Remove formatter usage; format manually or use an external tool.
gotcha The 'gren run' command requires the backend binary. If not found, it may fail silently. ↓
fix Set GREN_BIN environment variable to the backend executable path if needed.
gotcha Package manager rewritten in Gren in 0.6.0, enabling zero-install packages. However, old package caches may conflict. ↓
fix Delete old package cache at ~/.gren before upgrading.
Install
npm install gren-lang yarn add gren-lang pnpm add gren-lang Imports
- default wrong
const Compiler = require('gren-lang')correctimport Compiler from 'gren-lang' - compile
import { compile } from 'gren-lang/compiler' - run wrong
import { run } from 'gren-lang/run'correctimport { run } from 'gren-lang'
Quickstart
import { compile, run } from 'gren-lang';
import { readFileSync, writeFileSync } from 'fs';
const source = readFileSync('hello.gren', 'utf8');
const result = compile(source, { optimize: false });
if (result.type === 'error') {
console.error(result.errors);
process.exit(1);
}
writeFileSync('output.js', result.code);
console.log('Compilation succeeded.');
// To run:
run('hello.gren', { args: [] });