MyNixOS website logo
Description

An asynchronous modal FRP language.

This library implements the Async Rattus programming language as an embedded DSL. To this end the library provides a GHC plugin that checks the stricter typing rules of Async Rattus. What follows is a brief introduction to the language and its usage. A more detailed introduction can be found in this paper.

Async Rattus is a functional reactive programming (FRP) language that uses modal types to express temporal dependencies. In return the language will guarantee that programs are productive (in each computation step, the program makes progress), causal (output depends only on current and earlier input), and have no space leaks (programs do not implicitly retain memory over time).

The modal type constructor O (pronounced "later") is used to express the passage of time at the type level. Intuitively speaking, a value of type O a represents a computation that will produce a value of type a in the next time step. Additionally, the language also features the Box modal type constructor. A value of type Box a is a time-independent computation that can be executed at any time to produce a value of type a.

For example, the type of signals is defined as

data Sig a = a ::: (O (Sig a))

So the current value of the signal is available now, but its future state is only available in the next time step. Writing a map function for this type of streams, requires us to use the Box modality:

map :: Box (a -> b) -> Sig a -> Sig b
map f (x ::: xs) = unbox f x ::: delay (map f (adv xs))

This makes sure that the function f that we give to map is available at any time in the future.

The core of the language is defined in the module AsyncRattus.Primitives. Note that the operations on O and Box have non-standard typing rules. Therefore, this library provides a compiler plugin that checks these non-standard typing rules. To write Async Rattus programs, you must enable this plugin via the GHC option -fplugin=AsyncRattus.Plugin, e.g. by including the following line in the source file:

{-# OPTIONS -fplugin=AsyncRattus.Plugin #-}

Below is a minimal Async Rattus program using the AsyncRattus.Signal module for programming with signals:

{-# OPTIONS -fplugin=AsyncRattus.Plugin #-}

import AsyncRattus
import AsyncRattus.Signal

sums :: Sig Int -> Sig Int
sums = scan (box (+)) 0

The source code of the AsyncRattus.Signal module provides more examples on how to program in Async Rattus. An example project using Async Rattus can be found here.

Metadata

Version

0.2.0.2

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