corecursive-main: Write your main like it can call itself back.

[ bsd3, control, library, program ] [ Propose Tags ]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS]
Change log
Dependencies base (>=4.7 && <5), corecursive-main, process, unix [details]
License BSD-3-Clause
Copyright 2018 Lucas DiCioccio
Author Lucas DiCioccio
Revised Revision 1 made by LucasDiCioccio at 2018-09-16T20:26:26Z
Category Control
Home page
Bug tracker
Source repo head: git clone
Uploaded by LucasDiCioccio at 2018-08-19T13:58:05Z
Distributions NixOS:
Executables corecursive-main-exe
Downloads 899 total (10 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-08-19 [all 1 reports]

Readme for corecursive-main-

[back to package description]


Functional programmers are used to program with (co-)recursive functions. What if the main program was itself recursive? One could benefit the underlying operating system scheduler to orchestrate resources. For instance, limiting memory, file-descriptor on a per-recursive-call basis. Another instance is supporting distributed computations across multiple machines.

This package

This package demonstrates the idea of replacing the main entry-point of the program (i.e., main :: IO ()) with a recursion-aware main. The program first pattern matches on an "argument". This argument defines which action to take for the rest of the program. The rest of the program runs with a "Self-reference", which allows the program to call itself back. Explicitly passing a Self-reference is very similar to how the fix function allows to factor recursion out of the body of a self-referential function.

Unlike fix, which executes recursive-call in the same memory-space as the call-site, developper using this package need to teach the program to transfer arguments and return values back-and-forth the call-site and the execution site. This package minimizes the developper effort to perform this translation.

Currently, one mode is supported: spawning a child process on the same OS while serializing arguments over the command-line parameters.

Future versions of this package or sibling packages will likely provide:

  • support for 'JSON' or 'Dhall' serialization format
  • support for 'stdin' or networked serialization mechanisms
  • remote calls using ssh

Envisionned usages

Distributed computating:

  • run a same copy of the program on many places, each on a subset of the data (much like Map/Reduce)


  • use a single binary to reconfigure the whole datacenter and services after a cataclysmic outage (see #History) as well

  • orchestrate processes locally


This package is factored out of code and findings made while writing DepTrack. If you like this package you may find other interesting ideas in DepTrack.