papa: Type class-driven prelude with lens, comonads, and safe alternatives

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

Papa is a Haskell prelude that replaces the partial functions of Prelude with total ones, generalises the familiar names to type classes, and brings in lens, semigroupoids, bifunctors and comonad.

Total replacements

Total division takes a NonZero divisor, checked once by preview nonZero (divNonZero, divideNonZero, ratioNonZero, ...), and pow a Natural exponent, and intCast converts between integral types only where no value can be lost; Prelude's partial versions, with fromIntegral, are in the separate module Papa.Unsafe.Numeric. Elsewhere, where Prelude throws, Papa returns a Maybe: cycle (empty list), (!!), (!?) (index out of range), chr, succ, pred (out of range), stimes (count out of range) and readIO (no parse). On any Foldable1, maximum, minimum, maximumBy and minimumBy need no Maybe, and head, tail, last and init are lenses into a NonEmpty.

fromJust, read, error, undefined, throw, foldl1, foldr1, truncate, round, realToFrac and every unsafe* function are not exported (truncateMaybe, roundMaybe, floatToDouble, ... instead); a test fails to compile if they are.

Text first, and I/O errors as values

putStrLn, readFile, print, lines, words and the rest are Text's, read and write UTF-8 whatever the locale, read strictly, and return their IOException in IOExcept (ExceptT IOException IO) rather than throw it. catch, try and bracket never catch an asynchronous exception. The functions of text, bytestring, containers, vector and unordered-containers are wrapped, imported qualified, with a total function of the same name for each one that throws.

Generalised names

map is fmap, (++) is (<>), const is pure, mapM is traverse, fst and snd work on any tuple, lookup and partitionEithers work on any Foldable, and lefts and rights are traversals.

Usage

{-# LANGUAGE NoImplicitPrelude #-}
import Papa

average :: [Int] -> Maybe Int
average xs = fmap (divNonZero (sum xs)) (preview nonZero (length xs))

See Papa for the modules that import alongside it, and those to import qualified.

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
dev

Enable development warnings (-Werror)

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.5.0, 0.7.0
Change log changelog.md
Dependencies adjunctions (>=4 && <5), associative (<1), async (>=2.2.5 && <2.3), base (>=4.18 && <5), bifunctors (>=5 && <7), bytestring (>=0.11.2 && <0.13), comonad (>=5 && <6), containers (>=0.6.0.1 && <1), contravariant (>=1 && <2), deepseq (>=1.4 && <2), directory (>=1.3.8 && <1.4), distributive (<1), exceptions (>=0.10 && <0.11), filepath (>=1.4.100 && <1.6), free (>=5 && <6), hashable (>=1.4 && <1.6), id (<1), lens (>=5.2 && <6), mtl (>=2 && <3), one (>=0.0.4 && <1), polytree (<1), primitive (>=0.7 && <0.10), profunctors (>=5 && <6), selective (<1), semigroupoids (>=5 && <7), stm (>=2.5 && <2.6), text (>=2.0.2 && <2.2), time (>=1.12 && <1.16), transformers (>=0.5 && <1), unordered-containers (>=0.2.19 && <0.3), vector (>=0.13.2 && <0.14), witherable (<1) [details]
Tested with ghc ==9.6.7, ghc ==9.8.4, ghc ==9.10.3, ghc ==9.12.4, ghc ==9.14.1
License BSD-3-Clause
Copyright Copyright (c) 2016-2017 Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230 Copyright (c) 2017-2026 Tony Morris
Author Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Maintainer Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Uploaded by TonyMorris at 2026-11-24T21:38:07Z
Category Prelude
Home page https://gitlab.com/system-f/code/papa
Bug tracker https://gitlab.com/system-f/code/papa/issues
Source repo head: git clone git@gitlab.com:system-f/code/papa.git
Distributions
Reverse Dependencies 6 direct, 22 indirect [details]
Downloads 4363 total (48 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]