https://github.com/morloc-project/morloc
A typed, polyglot, functional language
https://github.com/morloc-project/morloc
code-generation functional-language interoperability language ontologies polyglot programming-language type-system
Last synced: 26 days ago
JSON representation
A typed, polyglot, functional language
- Host: GitHub
- URL: https://github.com/morloc-project/morloc
- Owner: morloc-project
- License: gpl-3.0
- Created: 2016-12-02T03:11:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-10-19T15:14:00.000Z (28 days ago)
- Last Synced: 2025-10-21T13:56:31.580Z (26 days ago)
- Topics: code-generation, functional-language, interoperability, language, ontologies, polyglot, programming-language, type-system
- Language: Haskell
- Homepage:
- Size: 6.11 MB
- Stars: 204
- Watchers: 6
- Forks: 5
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - morloc - project | 168 | (Haskell)
- programming-languages - morloc - Typed, polyglot, functional language. (Functional)
README
Manual |
Discord |
Paper Draft |
X |
BlueSky |
Email
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.
* 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 more
fast, 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).
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 (sumOfSums)
import types
source Py from "foo.py" ("pmap")
pmap a b :: (a -> b) -> [a] -> [b]
source Cpp from "foo.hpp" ("sum")
sum :: [Int] -> Int
--' Sum a list of lists of numbers
sumOfSums = sum . pmap sum
```
The imported code is 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 `int`s that returns an `int`:
```C++
// C++ code, in "foo.hpp"
#pragma once
#include
#include
int sum(std::vector xs) {
return std::accumulate(
xs.begin(), xs.end(), 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:
```
$ menv morloc make main.loc
$ menv ./nexus -h
Usage: ./nexus [OPTION]... COMMAND [ARG]...
Nexus Options:
-h, --help Print this help message
-o, --output-file Print to this file instead of STDOUT
-f, --output-format Output format [json|mpk|voidstar]
Exported Commands:
sumOfSums Sum a list of lists of numbers
param 1: [[Int]]
return: Int
$ menv ./nexus sumOfSums [[1,2,3],[4]]
10
```