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.
Go version 1.25 or higher.
$ go install github.com/hydromatic/morel-go/cmd/morel@latestThis puts a morel binary in $(go env GOPATH)/bin.
$ git clone git://github.com/hydromatic/morel-go.git
$ cd morel-go
$ go build ./cmd/morel; ./morel$ ./morel
morel-go v0.8.0 (go1.26.5, darwin/arm64)
- "Hello, world!";
val it = "Hello, world!" : stringType 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 listNamed files are run as scripts; a file argument of - means standard
input. Run ./morel --help for the full list of options.
Morel Go does not yet have documentation of its own; the language it implements is the one described by Morel Java.
- Morel Java language reference
- Query reference
- Datalog support
- "How to" guide
- Change log
- Reading test scripts can be instructive; try, for example, relational.smli or built-in.smli
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(includingval rec),fun,fn, and function applicationif,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
datatypeandtypedeclarationsraise, and the built-in exceptions- Relational expressions:
from,join(includingleft,rightandfullouter joins),where,group,compute,order,skip,take,yield,yieldAllandinto - Datalog
- The standard library: 460 members in 25 structures, based on the
Standard ML Basis Library
and extended with
Bag,Datalog,Interact,Range,Relational,SysandVariant - 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
.inputrcsupport, 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:
exceptiondeclarations, andhandlestructure,struct,signature,sig,openlocalwhile- 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.
- License: Apache License, Version 2.0
- Author: Julian Hyde (@julianhyde)
- Blog: http://blog.hydromatic.net
- Source code: https://github.com/hydromatic/morel-go
- Issues: https://github.com/hydromatic/morel-go/issues
- Change log and release notes