MyNixOS website logo
Description

A GHC plugin to remove support for recursion.

General recursion can be the cause of a lot of problems. This removes recursion from GHC, allowing you to guarantee you’re using other mechanisms, like recursion schemes.

NoRecursion plugin

A GHC plugin to remove support for recursion

General recursion can be the cause of a lot of problems. This removes recursion from GHC, allowing you to guarantee you’re using other mechanisms, like recursion schemes.

usage

Add no-recursion to your build dependencies.

Add -fplugin NoRecursion to your GHC options. This can be done per-module with

{-# OPTIONS_GHC -fplugin NoRecursion #-}

Now, any recursion in that module will result in a compilation failure.

NB: This won’t prevent you from using recursive functions imported from other modules, but inlined definitions from other modules will be checked.

allowing some recursion

NoRecursion supports two source annotations: "Recursion" and "NoRecursion".

You can re-enable recursion for individual top-level names like

recDef :: a -> b
recDef = myRecDef
{-# ANN recDef "Recursion" #-}

Or you can re-enable recursion for an entire module with

{-# ANN module "Recursion" #-}

And then you can re-disable recursion for individual names with

nonRecDef :: a -> a
nonRecDef = id
{-# ANN nonRecDef "NoRecursion" #-}

If both '"Recursion"' and "NoRecursion" annotations exist on the same name (or module), it’s treated as NoRecursion.

NB: If multiple names are mutually recursive, then they must all have recursion enabled to avoid being flagged by the plugin.

ANN has some caveats:

For more about how to use annotations, see the GHC User’s Guide.

licensing

This package is licensed under The GNU AGPL 3.0 or later. If you need a license for usage that isn’t covered under the AGPL, please contact Greg Pfeil.

When last checked, all transitive dependencies were licensed under The 3-Clause BSD License. However, you should review the license report for more details.

comparisons

Other projects similar to this one, and how they differ.

WartRemover

WartRemover is a Scala linting tool. A Recursion wart was added in 2017, and I’ve been meaning to write this plugin ever since. It only took seven years to find a few hours to make it happen …

Metadata

Version

0.1.2.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • 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