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

Composition

Morloc

compose functions across languages under a common type system

**Why use Morloc?** * Universal function composition: Import functions from multiple languages and compose them together under a unified, strongly-typed functional framework. * Polyglot without boilerplate: Use the best language for each task with no manual bindings or interop code. * Generate APIs, CLIs, and MCPs as views of the same underlying library with no extra code (or AI). * Morloc programs (and their API/CLI/MCP views) can be composed by simply importing them into a new Morloc module and re-exporting their functions. * Seamless benchmarking and testing: Swap implementations and run the same benchmarks/tests across languages with consistent type signatures and data representation. * Design universal libraries: Build abstract, type-driven libraries and populate them with foreign language implementations, enabling rigorous code organization and reuse. * Smarter workflows: Replace brittle application/file-based pipelines with faster, more maintainable pipelines made from functions acting on structured data. Below is a simple example, for installation details and more examples, see the [Manual](https://morloc-project.github.io/docs). mim run -- morloc install stdlib mim install main.loc mim expose add foo --as mcp,api mim start mim status claude mcp add --transport http foo http://127.0.0.1:9000/mcp curl -s http://127.0.0.1:9000/health curl -s http://127.0.0.1:9000/discover/foo | jq . curl -s -X POST -d '[[[1,2,3],[4,5]]]' http://127.0.0.1:9001/call/foo/vsum A Morloc module can import functions from foreign languages, assign them general types, and compose new functions: ```morloc -- Morloc code, in "main.loc" module m (vsum) import root-py import root-cpp source Py from "foo.py" ("pmap") pmap :: (a -> b) -> [a] -> [b] source Cpp from "foo.hpp" ("sum") sum :: [Real] -> Real --' Input numeric lists that will be summed in parallel --' metavar: LISTS type Lists = [[Real]] --' Sum a list of numeric lists --' return: Final sum of all elements in all lists vsum :: Lists -> Real vsum = sum . pmap sum ``` The imported code is natural code with no Morloc-specific dependencies. Below is the C++ code that defines `sum` as a function of a standard C++ vector of `double`s that returns a `double`: ```C++ // C++ code, in "foo.hpp" #pragma once #include #include double sum(std::vector xs) { return std::accumulate( xs.begin(), xs.end(), 0.0); } ``` Below is Python code that defines a parallel map function: ```python # Python code, in "foo.py" import multiprocessing as mp # Parallel map function def pmap(f, xs): with mp.Pool() as pool: results = pool.map(f, xs) return results ``` This program can be compiled and run as below: ``` $ morloc make main.loc $ ./nexus vsum -h Usage: ./nexus vsum LISTS Sum a list of numeric lists Positional arguments: LISTS Input numeric lists that will be summed in parallel type: [[Real]] Return: Real Final sum of all elements in all lists $ ./nexus vsum [[1.2],[0,0.1]] 1.3 ```