Function combinator "between" and derived combinators

Latest on Hackage:

See all snapshots between appears in

BSD-3-Clause licensed by Peter Trško
Maintained by [email protected]

Module documentation for

This version can be pinned in stack with:[email protected]:05c82afced3a60a6e7d624d6c1d410f6b1d3de264a663cc53237bef4b63e0322,2463


Hackage Hackage Dependencies Haskell Programming Language BSD3 License



It turns out that this combinator

f [email protected]~ g = (f .) . (. g)

is a powerful thing. It was abstracted from following (commonly used) pattern f . h . g where f and g are fixed.

This library not only define [email protected]~ combinator, but also some derived combinators that can help us to easily define a lot of things including lenses. See lens package for detais on what lenses are.

Function Data.Function.on can be implemented using [email protected]~ as:

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
on f g = (id [email protected]~ g [email protected]~ g) f

If function @[email protected] existed in /base/ then it could be defined as:

on3 :: (b -> b -> b -> d) -> (a -> b) -> a -> a -> a -> d
on3 f g = (id [email protected]~ g [email protected]~ g [email protected]~ g) f

For more examples see documentation.


Stable releases with API documentation are available on Hackage.

Building Options

  • -fpedantic (disabled by default)

    Pass additional warning flags to GHC.


The BSD 3-Clause License, see LICENSE file for details.


Contributions, pull requests and bug reports are welcome! Please don’t be afraid to contact author using GitHub or by e-mail (see .cabal file for that).


ChangeLog / ReleaseNotes


  • New function application combinators (new):
    • inbetween :: a -> b -> (a -> b -> r) -> r
    • (~$~) :: a -> b -> (a -> b -> r) -> r
    • (~$$~) :: b -> a -> (a -> b -> r) -> r
    • withIn :: ((a -> b -> r) -> r) -> (a -> b -> r) -> r
    • withReIn :: ((b -> a -> r) -> r) -> (a -> b -> r) -> r
  • Precursors to Iso, Lens and Prism (new):
    • type PreIso r s t a b = ((b -> t) -> (s -> a) -> r) -> r
    • type PreIso' r s a = PreIso r s s a a
    • type PreLens r s t a b = ((b -> s -> t) -> (s -> a) -> r) -> r
    • type PreLens' r s a = PreLens r s s a a
    • type PrePrism r s t a b = ((b -> t) -> (s -> Either t a) -> r) -> r
    • type PrePrism' r s a = PrePrism r s s a a
  • Uploaded to Hackage:


  • Original implementation moved to module Data.Function.Between.Lazy and is now reexported by Data.Function.Between. (new)
  • Implementation of strict variants of all functions defined in Data.Function.Between.Lazy module. These new functions use (f . g) x = f '$!' g '$!' x as definition for function composition where $! is strict application. (new)
  • Uploaded to Hackage:




Depends on 1 package(full list with versions):
Used by 1 package in lts-12.14(full list with versions):