morel

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

Build Status Go Reference

Morel

A functional query language, implemented in Go.

Morel is Standard ML with relational extensions: a from expression that queries collections the way SQL queries tables, but inside a language that has lambdas, polymorphism and pattern-matching.

Requirements

Go version 1.25 or higher.

Get Morel

Install
$ go install github.com/hydromatic/morel-go/cmd/morel@latest

This puts a morel binary in $(go env GOPATH)/bin.

Download and build
$ git clone git://github.com/hydromatic/morel-go.git
$ cd morel-go
$ go build ./cmd/morel; ./morel
Run the shell
$ ./morel
morel-go v0.8.0 (go1.26.5, darwin/arm64)
- "Hello, world!";
val it = "Hello, world!" : string

Type control+D to exit the shell.

Within the shell, the use function reads and evaluates source from a file:

- use "script.sml";

For quick testing, use the -e flag.

$ ./morel -e "1 + 2"
val it = 3 : int

$ ./morel -e "from i in [1,2,3] where i > 1"
val it = [2,3] : int list

$ ./morel -e 'let fun double x = x * 2 in map double [2,3,4] end'
val it = [4,6,8] : int list

Named files are run as scripts; a file argument of - means standard input. Run ./morel --help for the full list of options.

Documentation

Morel Go does not yet have documentation of its own; the language it implements is the one described by Morel Java.

Status

Morel Go aims to be compatible with the Morel language as implemented by Morel Java, and its strategy is to copy that project's .smli test scripts and get them to pass. Compatibility is therefore measured by how much of Morel Java's script corpus Morel Go reproduces line for line: currently about 87%. (See "Morel on Go" for how the port was done.)

Implemented:

  • Literals, variables, and comments
  • let, val (including val rec), fun, fn, and function application
  • if, case, and pattern-matching over constants, wildcards, tuples, records, and lists
  • Type inference (Hindley-Milner) and type variables
  • Primitive, function, list, bag, tuple, record, and vector types
  • datatype and type declarations
  • raise, and the built-in exceptions
  • Relational expressions: from, join (including left, right and full outer joins), where, group, compute, order, skip, take, yield, yieldAll and into
  • Datalog
  • The standard library: 460 members in 25 structures, based on the Standard ML Basis Library and extended with Bag, Datalog, Interact, Range, Relational, Sys and Variant
  • A shell that reads scripts or standard input, evaluates a single expression with -e, and checks a script against its expected output in .smli (idempotent) format

Not implemented:

  • exception declarations, and handle
  • structure, struct, signature, sig, open
  • local
  • while
  • References, and operators ! and :=
  • User-defined operators (infix, infixr)
  • Overloaded functions (over, val inst); they parse, but do not compile
  • External data: reading from the file system, or from a database via ODBC or JDBC
  • Attributes ([@ ... ]) and quoted identifiers
  • Command-line editing and history in the shell; there is no up-arrow recall, and nothing is saved between sessions

See also GitHub issues.

More information

Documentation

Overview

Package morel is the root of morel-go, an interpreter for Morel, a functional query language. The implementation lives under internal/; the command lives under cmd/morel.

Directories

Path Synopsis
cmd
morel command
Command morel is an interpreter for Morel, a functional query language.
Command morel is an interpreter for Morel, a functional query language.
internal
ast
Package ast defines the abstract syntax tree that the parser produces: the user-facing representation, with source spans, before type resolution converts it to Core.
Package ast defines the abstract syntax tree that the parser produces: the user-facing representation, with source spans, before type resolution converts it to Core.
compile
Package compile turns the AST into the typed Core IR: the TypeResolver deduces a type for every node by unification, and the Resolver converts the AST to Core using those types.
Package compile turns the AST into the typed Core IR: the TypeResolver deduces a type for every node by unification, and the Resolver converts the AST to Core using those types.
core
Package core defines Morel's typed intermediate representation.
Package core defines Morel's typed intermediate representation.
datalog
Package datalog implements the Souffle-flavored Datalog dialect behind the Datalog built-in structure: a parser, an analyzer (declarations, rule safety, stratification), and a translator that emits Morel source whose recursion is a Relational.iterate fixpoint.
Package datalog implements the Souffle-flavored Datalog dialect behind the Datalog built-in structure: a parser, an analyzer (declarations, rule safety, stratification), and a translator that emits Morel source whose recursion is a Relational.iterate fixpoint.
eval
Package eval holds runtime values and the built-in functions.
Package eval holds runtime values and the built-in functions.
parse
Package parse holds the Morel lexer and parser.
Package parse holds the Morel lexer and parser.
pp
Package pp is a pretty-printer that lays out a document within a line-width limit.
Package pp is a pretty-printer that lays out a document within a line-width limit.
shell
Package shell contains the kernel, the script runner, and the statement splitter.
Package shell contains the kernel, the script runner, and the statement splitter.
sig
Package sig reads the subset of the built-in library's signature files (lib/*.sig) that gives the types of built-in values.
Package sig reads the subset of the built-in library's signature files (lib/*.sig) that gives the types of built-in values.
token
Package token defines the lexical tokens of Morel and their source positions.
Package token defines the lexical tokens of Morel and their source positions.
types
Package types defines Morel's types and the system that interns them.
Package types defines Morel's types and the system that interns them.
unify
Package unify implements the Martelli-Montanari unification algorithm, with action hooks that fire as variables resolve and constraints that model overloaded operators.
Package unify implements the Martelli-Montanari unification algorithm, with action hooks that fire as variables resolve and constraints that model overloaded operators.
Package lib embeds the built-in library sources: the signatures (*.sig), which give the types of the built-ins, and the Morel sources (*.sml) that define the derivable members of some structures.
Package lib embeds the built-in library sources: the signatures (*.sig), which give the types of the built-ins, and the Morel sources (*.sml) that define the derivable members of some structures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL