MyNixOS website logo
Description

Write your main like it can call itself back.

corecursive-main

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)

Dev/Ops:

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

  • orchestrate processes locally

History

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.

Metadata

Version

0.1.0.0

Executables (1)

  • bin/corecursive-main-exe

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows