BSD-3-Clause licensed by Sven Heyll
Maintained by [email protected]
This version can be pinned in stack with:function-builder-0.3.0.1@sha256:48ae4642440dda57fbffe4055ef4af96bd760d7996b18af2d74afa0002cb8a70,3335

Module documentation for 0.3.0.1

Depends on 2 packages(full list with versions):

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

  • polyToMonoid

  • HoleyMonoid

  • formatting

  • category-printf I learned from the author of that library Cale Gibbard in this reddit comment that the Format type in that library (called FunctionBuilder in this library) is an alias for

    “(…)the cokleisli category for the comonad of functions on a monoid, which is already in the comonad library”

Changes

Changelog for function-builder

0.3.0.1

  • Fix markdown formatting in Changelog
  • Specify the dependency versions according to the PVP (hopefully)

0.3.0.0

  • Update README with Cokleisli ((->) w) a b ~ FunctionBuilder w a b
  • Re-introduce immediate renamed to deferred
  • Remove HasParameter
  • Fix some typos
  • Add unit tests

0.2.0.1

  • Update README

0.2.0.0

  • Clean up and renamings
  • Add a type class for types that dont add values to the function builder outpout.

0.1.2.0

  • Add a type class for function builders that add a parameter to the generated function

0.1.1.0

  • Add a type class for function builders

0.1.0.4

  • Fix reference to the ‘formatting’ library

0.1.0.3

  • Add reference to the ‘formatting’ library

0.1.0.2

  • Improve documentation

0.1.0.1

  • Fix Cabal build issues

0.1.0.0

  • Initial Release