morloc: A multi-lingual, typed, workflow language

[ code-generation, compiler, gpl, language, library, program ] [ Propose Tags ]


  • Morloc
    • CodeGenerator
      • Morloc.CodeGenerator.Generate
      • Grammars
        • Morloc.CodeGenerator.Grammars.Common
        • Morloc.CodeGenerator.Grammars.Macro
        • Translator
          • Morloc.CodeGenerator.Grammars.Translator.Cpp
          • Morloc.CodeGenerator.Grammars.Translator.Python3
          • Morloc.CodeGenerator.Grammars.Translator.R
          • Source
            • Morloc.CodeGenerator.Grammars.Translator.Source.CppInternals
      • Morloc.CodeGenerator.Internal
      • Morloc.CodeGenerator.Namespace
      • Morloc.CodeGenerator.Nexus
      • Morloc.CodeGenerator.Serial
    • Morloc.Config
    • Data
      • Morloc.Data.DAG
      • Morloc.Data.Doc
      • Morloc.Data.Text
    • Morloc.Error
    • Frontend
      • Morloc.Frontend.API
      • Morloc.Frontend.Desugar
      • Morloc.Frontend.Infer
      • Morloc.Frontend.Internal
      • Lang
        • Morloc.Frontend.Lang.DefaultTypes
      • Morloc.Frontend.Namespace
      • Morloc.Frontend.Parser
      • Morloc.Frontend.PartialOrder
      • Morloc.Frontend.Pretty
      • Morloc.Frontend.Treeify
    • Morloc.Internal
    • Morloc.Language
    • Morloc.Module
    • Morloc.Monad
    • Morloc.Namespace
    • Morloc.Pretty
    • ProgramBuilder
      • Morloc.ProgramBuilder.Build
    • Morloc.Quasi
    • Morloc.System


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS] 0.33.0
Change log
Dependencies aeson (>= && <1.3), base (>=4.7 && <5), bytestring (>= && <0.11), containers (>= && <0.6), directory (>= && <1.4), docopt (>= && <0.8), extra (>=1.6.5 && <1.7), filepath (>= && <1.5), haskell-src-meta (>= && <0.9), megaparsec (>=6.4.1 && <6.5), morloc, mtl (>=2.2.2 && <2.3), parsec (>= && <3.2), partial-order (>= && <0.2), pretty-simple (>= && <2.2), prettyprinter (>= && <1.3), prettyprinter-ansi-terminal (>= && <1.2), process (>= && <1.7), raw-strings-qq (>=1.1 && <1.2), safe (>=0.3.17 && <0.4), scientific (>= && <0.4), template-haskell (>= && <2.13), text (>= && <1.3), unordered-containers (>= && <0.3), yaml (>=0.8.29 && <0.9) [details]
License GPL-3.0-only
Copyright 2020 Zebulun Arendsee
Author Zebulun Arendsee
Category Language, Compiler, Code Generation
Home page
Bug tracker
Source repo head: git clone
Uploaded by arendsee at 2020-11-06T07:59:22Z
Executables morloc
Downloads 183 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2020-11-06 [all 2 reports]

Readme for morloc-0.33.0

[back to package description]

experimental travis build status github release license: GPL v3 DOI

morloc is a functional programming language where functions are imported from foreign languages and unified under a common type system. The compiler generates the code needed to compose functions across languages and also to direct automation of mundane tasks such as data validation, type/format conversions, data caching, distributed computing, and file reading/writing. The endgame is to develop morloc into a query language that returns optimized programs from an infinite library of functions and compositions of functions.

See the manual for more information.

If you want to get straight to playing with code, go through the steps in the installation section and then go to the project in demo/01_sequence_analysis.


This project is under active development with no stability guarantees until the v1.0 release. Pull requests, issue reports, and private messages are very welcome.


Compile and install the package (requires the Haskell utility stack):

git clone
cd morloc
stack install --fast

morloc also depends on the JSON::XS perl module from CPAN, which can be installed as follows:

sudo perl -MCPAN -e 'install JSON::XS' 

For Python support, you need to download the pymorlocinternals library from PyPi:

pip install pymorlocinternals
# or on Mac:
pip3 install pymorlocinternals

For R support, you need to install the rmorlocinternals library from github, in an R session, run:

R> install.packages("devtools")
R> devtools::install_github("morloc-project/rmorlocinternals")

C++ support currently requires a GNU compiler that supports C++11.

morloc modules can be installed from the morloc library with the commands such as:

morloc install cppbase
morloc install pybase
morloc install rbase
morloc install math

The morloc install commands will install the modules in the $HOME/.morloc/lib folder.

Last of all, if you are working in vim, you can install morloc syntax highlighting as follows:

mkdir -p ~/.vim/syntax/
mkdir -p ~/.vim/ftdetect/
cp vim-syntax/loc.vim ~/.vim/syntax/
echo 'au BufRead,BufNewFile *.loc set filetype=loc' > ~/.vim/ftdetect/loc.vim

Getting Started

export hello
hello = "Hello World"

The "export" keyword exports the variable "hello" from the module.

Paste this into a file (e.g. "hello.loc") and then it can be imported by other morloc modules or directly compiled into a program where every exported term is a subcommand.

morloc make hello.loc

This will generate a single file named "". The nexus is the executable script that the user will interact with. For this simple example, it is the only generated file. It is currently written in Perl.

Calling "" with no arguemtns or with the -h flag, will print a help message:

$ ./ -h
The following commands are exported:
    return: Str

The return: Str phrases states that hello returns a string value.

The command hello can be called as shown below:

$ ./ hello
Hello World

Composing C++ Functions

The following code uses only C++ functions (fold, map, add and mul).

import cppbase (fold, map, add, mul)

export square;
export sumOfSquares;

square x = mul x x;

sumOfSquares xs = fold add 0 (map square xs);

If this script is pasted into the file "example-1.loc", it can be compiled as follows:

morloc install cppbase
morloc make example-1.loc

The install command clones the cppbase repo from github repo into the local directory ~/.morloc/lib. The morloc make command will generate a file named, which is an executable interface to the exported functions.

You can see typed usage information for the exported functions with the -h flag:

$ ./ -h
The following commands are exported:
    param 1: Num
    return: Num
    param 1: [Num]
    return: Num

Then you can call the exported functions (arguments are in JSON format):

$ ./ sumOfSquares '[1,2,3]'

The executable dispatches the command to the compiled C++ program, pool-cpp.out.

Language interop

morloc can compose functions across languages. For example:

import math (fibonacci);
import rbase (plotVectorPDF, ints2reals);

export fibplot

fibplot n = plotVectorPDF (ints2reals (fibonacci n)) "fibonacci-plot.pdf";

The fibplot function calculates Fibonacci numbers using a C++ function and plots it using an R function. The R function plotPDF is a perfectly normal R function with no extra boilerplate:

plotPDF <- function(x, filename){

The Morloc Type System

The first level of the morloc type system is basically System F extended across languages. A given function will have a general type as well as a specialized type for each language it is implemented in.

The map function has the types

map :: (a -> b) -> [a] -> [b]
map Cpp :: (a -> b) -> "std::vector<$1>" a -> "std::vector<$1>" b
map Python3 :: (a -> b) -> list a -> list b

The general signature looks almost the same as the Haskell equivalent (except that morloc universal quantification is currently explicit). The list type constructors for C++ are very literally "type constructors" in that they are used to create syntactically correct C++ type strings. If the type variable a is inferred to be int, for example, then the C++ type std::vector<int> will be used in the generated code. The same occurs in the python type constructors list, except here the same Python type is generated regardless of the type of a.

The following example is available in examples/rmsWithTypes.loc:

import cppbase (fold, map, add, mul)

export square;
export sumOfSquares;

square x = mul x x;

sumOfSquares xs = fold add 0 (map square xs);

This example cannot be compiled since none of the functions are imported or sourced, but it can be typechecked:

morloc typecheck examples/rmsWithTypes.loc
add :: Num -> Num -> Num;
add Cpp :: double -> double -> double;

mul :: Num -> Num -> Num;
mul Cpp :: double -> double -> double;

fold     :: (b -> a -> b) -> b -> [a] -> b;
fold Cpp :: (b -> a -> b) -> b -> "std::vector<$1>" a -> b;

map :: (a -> b) -> [a] -> [b];
map Cpp :: (a -> b) -> "std::vector<$1>" a
                    -> "std::vector<$1>" b;

square x = mul x x;
sumOfSquares xs = fold add 0 (map square xs);

The typechecker associates each sub-expression of the program with a set of types. The specific type information in mul is sufficient to infer concrete types for every other C++ function in the program. The inferred C++ type of sumOfSquares is

"std::vector<$1>" double -> double

The general type for this expression is also inferred as:

List Num -> Num

The concrete type of mul is currently written as a binary function of doubles. Ideally this function should accept any numbers (e.g., an int and a double). I intend to add this functionallity eventually, perhaps with a Haskell-style typeclass system.