MyNixOS website logo
Description

Create poly variadic functions for monoidal results.

Please see README.md

Build Status

Hackage

A library for making Monoid writing functions with variable number of parameters

Also known as: Holey monoids.

This library is made to be useful especially for library authors, who want to provide users with building blocks to create functions that compose a monoidal structure from their parameters in a type safe way. Think of printf.

This library allows the author of such a library to easily add the building blocks, allowing users to build poly variadic functions, i.e. with parameters depending on the order and composition of these building blocks.

Several FunctionBuilder values sharing a common monoidal output type can be composed to a big FunctionBuilder value, in order to build an output function that has a flexible number and types of parameters depending, on the individual FunctionBuilders used. This output function can be obtained by toFunction.

FunctionBuilders can also be composed via standard type classes.

This module gives you ready-made Functor, Applicative, Semigroup, Monoid and Category` instances;

For example, this library could be used to build a string formatting library, that allows users to compose arbitrary, printf-style render functions from reusable building blocks, such that they can be re-combined in order to make get functions, that can be applied to parameters that fill place holders, like e.g.:

 module AStringFormatter where

 str :: String -> FunctionBuilder String next next
 str = immediate

 renderInt :: FunctionBuiler String next (Int -> next)
 renderInt = deferred show

 renderFloat :: FunctionBuiler String next (Float -> next)
 renderFloat = ...

Then the user of YourStringFormatter can write:

 module CpuTempFormatter where

 import AStringFormatter

 renderCpuTemp :: Int -> Float -> String
 renderCpuTemp =
   toFunction (str "CPU " . renderInt . str " Temperature: " . renderFloat)

Similar Libraries

Metadata

Version

0.3.0.1

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