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

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

Papa is a curated Haskell prelude that re-exports only total, safe functions and integrates seamlessly with the modern Haskell ecosystem. It eliminates partial functions while providing comprehensive type class coverage across base, lens, bifunctors, semigroupoids, comonads, profunctors, and more.

Core Design Principles

  • No Partial Functions — All re-exported functions are total and safe

  • Type Class-Driven — Maximizes use of standard type classes for polymorphic code

  • Optics Integration — Full lens support with indexed operations and plated recursion

  • Modern Ecosystem — Integrates adjunctions, comonads, profunctors, selective functors, and more

What's Included

Papa provides a comprehensive set of type classes and operations:

  • Base functionality — Safe alternatives to Prelude with Eq1Eq2, Ord1Ord2, Show1/Show2

  • Functor hierarchy — Functor, Applicative, Monad, Alternative, MonadPlus, with Apply/Bind

  • Foldable/Traversable — Including Foldable1/Traversable1 for non-empty structures

  • Lens integration — Full optics support with At, Ixed, Plated, IndexedPlated, Field1-9

  • Bifunctors — Bifunctor, Bifoldable, Bitraversable with indexed variants

  • Comonads — Comonad, ComonadApply, Env, Store, Traced comonads

  • Profunctors — Strong, Choice, Closed profunctors (import qualified)

  • Containers — Map, Set, IntMap, IntSet, Seq, Tree (import qualified)

  • Free structures — Free monads and Cofree comonads

  • Transformers — MonadTrans, MonadIO, mtl classes (MonadReader, State, Writer, etc.)

  • Specialized functors — Contravariant, Distributive, Selective, Witherable

  • Generic programming — Generic, Generic1, Data, Typeable

  • Performance — NFData for strict evaluation, all utility functions marked INLINE

Forbidden Functions

Papa explicitly does NOT export these partial functions:

  • head, tail, init, last — Use optics or pattern matching

  • (!!) — Use safe (^? ix n) from lens (Papa provides a safe version)

  • maximum, minimum — Use maximum1/minimum1 for non-empty structures

  • foldl1, foldr1 — Use Foldable1 versions

  • fromJust — Use fromMaybe or pattern matching

  • read — Use readMaybe or parser libraries

  • error, undefined — Use typed errors with Either

  • All unsafe* functions

Usage

{-# LANGUAGE NoImplicitPrelude #-}
import Papa

-- Use safe, total functions
safeHead :: [a] -> Maybe a
safeHead = (^? ix 0)

-- Leverage type classes
genericLength :: (Foldable f, Num n) => f a -> n
genericLength = foldl' (\n _ -> n + 1) 0

-- Work with lenses
data Person = Person { _name :: String, _age :: Int }
name :: Lens' Person String

Some modules require qualified import to avoid name conflicts:

import qualified Papa.Containers.Data.Map as Map
import qualified Papa.Profunctors.Data.Profunctor as Profunctor

Future Plans

Note: Future versions may split this package into separate dependencies to reduce compilation times and allow finer-grained control over transitive dependencies. The current monolithic structure prioritizes ease of use and comprehensive type class coverage, but may be reorganized as:

  • papa-base — Core prelude with base, bifunctors, semigroupoids

  • papa-lens — Lens integration and optics

  • papa-comonad — Comonad hierarchy

  • papa-transformers — MTL and transformer classes

  • papa-ecosystem — Profunctors, selective, witherable, etc.

This reorganization would allow users to depend only on the pieces they need while maintaining API compatibility through the top-level papa package as a convenience re-export.

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
Change log changelog.md
Dependencies adjunctions (>=4 && <5), associative (<1), base (>=4.11 && <6), bifunctors (>=5 && <7), comonad (>=5 && <6), containers (>=0.5 && <1), contravariant (>=1 && <2), deepseq (>=1.4 && <2), distributive (<1), free (>=5 && <6), id (<1), lens (>=4 && <6), mtl (>=2 && <3), one (>=0.0.4 && <1), polytree (<1), profunctors (>=5 && <6), selective (<1), semigroupoids (>=5 && <7), transformers (>=0.5 && <1), witherable (<1) [details]
Tested with ghc ==9.6.7, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.4
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-07-09T04:58:41Z
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 4238 total (35 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-07-09 [all 1 reports]