morloc README

The project's README from github.com/morloc-project/morloc. As one markdown file: README.md.

github release   license: Apache 2.0   Manual   Discord   Paper   X   BlueSky   Email

Composition

Morloc

Make the function, not the application, the unit of composition

Morloc composes functions across languages under a common type system and transforms modules into rich CLIs, APIs, and MCPs.

Write ordinary code in ordinary languages, source it into a Morloc script, and provide a type. These functions are then first class citizens. They can be used freely within a rich functional language. The Morloc compiler generates the CLI, API, MCP model, and usage statements from the types and declarative docstring instructions.

Install

Morloc runs natively on Linux, macOS (new ARM chips), and Windows WSL.

Run this to install the Morloc Installation Manager (mim):

curl -fsSL https://raw.githubusercontent.com/morloc-project/morloc-manager/main/scripts/install.sh | sh
mim new     # bulid the environment
mim shell   # drop into a shell
mim demo    # pull cool morloc demos

The build is native by default, add the --engine docker flag to build in a container (or podman or apptainer). The environment automatically handles dependencies for Morloc builds via the Pixi package manager. See the manual section Getting Started for more info.

You may freeze Morloc environments into Docker images with mim freeze.

An example

Two functions, in two languages, neither aware of the other. A C++ sum:

// foo.hpp
#pragma once
#include <vector>

double sum(const std::vector<double>& vec) {
    double sum = 0.0;
    for (double value : vec) {
        sum += value;
    }
    return sum;
}

and a parallel map in Python:

# foo.py
import multiprocessing as mp

def pmap(f, xs):
    with mp.Pool() as pool:
        results = pool.map(f, xs)
    return results

Neither file imports anything from Morloc. The Morloc module gives each a type and composes them:

-- sums.loc
module m (sum, sumOfSums)

import root-py
import root-cpp

source Py from "foo.py" ("pmap")
source Cpp from "foo.hpp" ("sum")

pmap :: (a -> b) -> [a] -> [b]

--' Add up a list of numbers
sum :: [Real] -> Real

--' Add up a list of lists, summing each in parallel
sumOfSums :: [[Real]] -> Real
sumOfSums = sum . pmap sum

. is function composition, so sumOfSums reads right to left: pmap sum sums each inner list in parallel, and the outer sum adds the results.

$ morloc make sums.loc
$ ./sums sumOfSums '[[1,2],[3,4,5]]'
15

A Python function called a C++ function across a process boundary, and you wrote no binding, no serializer, and no argument parser.

Free stuff that the compiler generates based on the type

Building the program creats a CLI tool from the given types and docstrings:

$ ./sums -h
Usage: ./sums <nexus_options> <command> <command_options>

Commands:
  sum        Add up a list of numbers
  sumOfSums  Add up a list of lists, summing each in parallel

General Options:
  -h, --help  Print help; -hh adds details and examples, -hhh adds schemas
              (nexus options: -h @)

./sums sum -h goes further and prints the argument types the compiler derived.

It can also serve as an MCP server (./sums --mcp-tools emits JSON Schema tool definitions), an HTTP, TCP, and Unix-socket service, and a module that another Morloc module can import and re-export. None of these are separate builds or a separate descriptions, so none of them can drift from the functions: changing a return type changes all interfaces.

Where the project stands

Morloc has been in development for about ten years and is in beta. I use it for my own work and am currently trying to build a community.

The test suite is massive and growing, but many bugs remain. The core feature is slowly stabilizing, but I still make regular backwards incompatible changes. Play with the cutting edge and you might bleed. Track your blood over here: issue tracker.

Getting involved

The hard part is finished. The ongoing work is the long tail of bug fixes and ecosystem development. That is where I need people. Here's what I'm looking for:

If you are interested in playing with Morloc (or want to drown my in money), feel free to contact me at [email protected].

License

Apache 2.0. See LICENSE.

morloc (morloc-project/morloc)

Searching Database…

219 ·GitHub
这是什么?Morloc 是一个强类型的多语言编译器:它用一套统一的类型系统把不同语言写的函数组合在一起,并把每个模块变成一个 CLI、一个 API 和一个 MCP 服务器。
它是编程语言、编译器,还是框架?它是一个编译器,编译它自己的一个小型函数式脚本语言。你用普通语言写函数,把它们引入 Morloc 脚本,给它们标注类型,其余的东西都由编译器生成。
我怎么安装和构建它?运行安装脚本,获得 Morloc Installation Manager (mim),它可以在 Linux、新款 ARM 芯片的 macOS 以及 Windows WSL 上原生构建 Morloc。加上 --engine docker 参数,就可以改为在容器里构建。
我需要先安装别的东西吗?不需要手动装任何东西:mim 会通过 Pixi 包管理器自动拉取构建依赖。只有在容器化构建时才需要 Docker、Podman 或 Apptainer,mim freeze 还可以把一个环境打包成 Docker 镜像。
它稳定到可以拿来构建项目吗?还不行:经过大约十年的开发,Morloc 仍处于 beta 阶段,还有不少 bug,作者也经常做出不向后兼容的改动。玩最前沿的东西,可能会见血。
在 Morloc 里,Python 函数怎么调用 C++ 函数?编译器会生成全部粘合代码:调用跨越进程边界进行,你不用写绑定、序列化器或参数解析器——只要在 Morloc 模块里给这两个函数标注类型就行。
构建一个 Morloc 模块后,我能得到什么?一次构建会生成一个带自动帮助文本的 CLI、一个 MCP 服务器(--mcp-tools 会输出 JSON Schema 格式的工具定义)、一个 HTTP、TCP 和 Unix 套接字服务,以及一个可导入的模块——全部由同一套类型生成,所以接口不会和代码脱节。
我的函数可以用哪些语言来写?README 演示了 C++ 和 Python 并肩协作,Morloc 本身也明确支持多语言。语言支持还在不断扩展——作者欢迎贡献者把新语言带进这个生态。
作者说最难的部分已经完成,他需要什么样的帮助?bug 报告、给你已经维护的库编写带类型的模块、编辑器工具、新语言,以及类型系统理论。联系方式是 [email protected]。
What are similar projects?swift, unison, crystal, reason, scala, TypeScript, carbon-lang, elixir
Size
23.1 MB
Stars
219
Age
9y
Commits · 90 Days