@hackage / papa

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

Latest0.5.0

About

Metadata

  • Last updated , by TonyMorris
  • License BSD-3-Clause
  • Categories Prelude
  • Maintained by: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>

  • Lottery factor: 1

Links

Installation

Tested Compilers

  1. 9.10.1
  2. 9.8.4
  3. 9.6.7

Package Flags

Use the -f option with cabal commands to enable flags

    dev (off by default)

    Enable development warnings (-Werror)

Readme

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.