inj: A class for injective (one-to-one) functions

[ bsd3, control, library ] [ Propose Tags ] [ Report a vulnerability ]

An injection is a function that never maps distinct elements of the domain to the same element of the codomain. For example, (\x -> x + 1) is an injection, but (\x -> min x 0) is not. . This package provides the Inj class, whose instances can be composed to construct nested structures from singleton elements.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0, 2.0
Change log CHANGELOG.md
Dependencies base (>=4.16 && <5) [details]
Tested with ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.7, ghc ==9.8.4, ghc ==9.10.3, ghc ==9.12.4, ghc ==9.14.1
License BSD-3-Clause
Author Vladislav Zavialov
Maintainer Vladislav Zavialov <vlad.z.4096@gmail.com>
Uploaded by int_index at 2026-09-03T18:02:48Z
Category Control
Source repo head: git clone https://github.com/int-index/inj.git
Distributions LTSHaskell:1.0, Stackage:2.0
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 1907 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for inj-2.0

[back to package description]

inj

A class for injective (one-to-one) functions.

An injection is a function that never maps distinct elements of the domain to the same element of the codomain. For example, \x -> x + 1 is an injection, but \x -> min x 0 is not.

class Inj p a where
  inj :: p -> a

The instances compose, so inj can construct nested structures from singleton elements, wrapping and converting as needed:

ghci> inj 'a' :: Maybe [Char]
Just "a"

ghci> inj True :: Maybe [Bool]
Just [True]

ghci> inj (5 :: Int) :: Maybe Double
Just 5.0

ghci> inj [1, 2, 3 :: Int] :: [Double]
[1.0,2.0,3.0]

ghci> inj (True, 2 :: Int) :: (Maybe Bool, [Double])
(Just True,[2.0])

By convention, the instances of Inj never match on p and always match on a. This guarantees that users will not encounter overlapping instances.

Instances for base types are provided by this package. Before version 2.0 they lived in a separate inj-base package; see the changelog for migration notes.