Skip to content

Repository files navigation

Build Status Go Reference Morel mushroom (credit: OldDesignShop.com)

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
  • Command-line editing in the shell, with Emacs and Vi bindings and .inputrc support, and history that persists across sessions in ~/.morel/history-go
  • Syntax highlighting in the shell, with a color scheme deduced from the terminal's background or named by --color-scheme

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
  • Tab completion in the shell

See also GitHub issues.

More information

About

A functional query language, implemented in Go

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages