Moduleone-liner-2.1Haskell2010
Generics.OneLiner
All functions without postfix are for instances of Generic, and functions
with postfix 1 are for instances of Generic1 (with kind Type -> Type) which
get an extra argument to specify how to deal with the parameter.
Functions with postfix 01 are also for Generic1 but they get yet another
argument that, like the Generic functions, allows handling of constant leaves.
The function createA_ does not require any such instance, but must be given
a constructor explicitly.
- 9 types
- 11 classes
- 44 values
- Packageone-liner-2.1
- Exports65
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceOneLiner.hs
Producing values
7 declarationsCreate a value, given a constructor (or a function) and how to construct its components, under an applicative effect.
For example, this is the implementation of Test.QuickCheck.arbitrary for a
type with a single constructor (e.g., quadruples (,,,)).
arbitrary = createA_ @Arbitrary arbitrary (,,,)
Traversing values
12 declarationsMap each component of a structure to a linear monoid, and combine the results.
For example. this could be the default implementation of Consumable:
consume = glfoldMap @Consumable consume
glfoldMap is gltraverse specialized to Const.
Map each component of a structure to an action linearly, evaluate these actions from left to right, and collect the results.
For example. this could be the default implementations of Dupable and Movable:
dupV = gltraverse @Dupable Linear.dupV
move = gltraverse @Movable move
gltraverse is generic specialized to linear Kleisli.
traverse = gtraverse1 @Traversable traverse
gtraverse1 is generic1 specialized to Star.
traverse = gltraverse1 @Traversable traverse
gltraverse1 is generic1 specialized to linear Kleisli.
gltraverse01 is generic01 specialized to linear Kleisli, requiring Movable for constants.
Combining values
6 declarationsVariant of mzipWith1 where you can choose the value which is returned when the constructors don't match.
Consuming values
2 declarationsFunctions for records
8 declarationsThese functions only work for single constructor data types.
cotraverse = gcotraverse1 @Distributive cotraverse
gcotraverse1 is record1 specialized to Costar.
Generic programming with profunctors
9 declarationsAll the above functions have been implemented using these functions,
using different profunctors.
Classes
class (Profunctor p, GenericUnitProfunctor p, GenericProductProfunctor p) => GenericRecordProfunctor (p :: Type -> Type -> Type)A generic function using a GenericRecordProfunctor works on any data type with exactly one constructor, a.k.a. records, with multiple fields (mult) or no fields (unit).
GenericRecordProfunctor is similar to ProductProfuctor from the
product-profunctor package, but using types from GHC.Generics.
Instances1GenericRecordProfunctor
(Profunctor p, GenericUnitProfunctor p, GenericProductProfunctor p) => GenericRecordProfunctor pDefined in one-liner-2.1 · Generics.OneLiner.Classes
class (GenericRecordProfunctor p, GenericSumProfunctor p) => GenericNonEmptyProfunctor (p :: Type -> Type -> Type)A generic function using a GenericNonEmptyProfunctor works on any data type with at least one constructor.
Instances1GenericNonEmptyProfunctor
(GenericRecordProfunctor p, GenericSumProfunctor p) => GenericNonEmptyProfunctor pDefined in one-liner-2.1 · Generics.OneLiner.Classes
class (GenericNonEmptyProfunctor p, GenericEmptyProfunctor p) => GenericProfunctor (p :: Type -> Type -> Type)A generic function using a GenericProfunctor works on any
algebraic data type of kind Type, including those with no constructors and constants.
Instances1GenericProfunctor
(GenericNonEmptyProfunctor p, GenericEmptyProfunctor p) => GenericProfunctor pDefined in one-liner-2.1 · Generics.OneLiner.Classes
class (GenericProfunctor p, GenericConstantProfunctor p) => Generic1Profunctor (p :: Type -> Type -> Type)A generic function using a Generic1Profunctor works on any
algebraic data type of kind Type -> Type, including those with no constructors and constants.
Instances1Generic1Profunctor
(GenericProfunctor p, GenericConstantProfunctor p) => Generic1Profunctor pDefined in one-liner-2.1 · Generics.OneLiner.Classes
Instances13GenericUnitProfunctor, …
Applicative f => GenericUnitProfunctor (Zip f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericUnitProfunctor (Kleisli f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericUnitProfunctor CtorDefined in one-liner-2.1 · Generics.OneLiner.InternalGenericUnitProfunctor TaggedDefined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericUnitProfunctor (Star f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesFunctor f => GenericUnitProfunctor (Costar f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericUnitProfunctor (->)Defined in one-liner-2.1 · Generics.OneLiner.ClassesDivisible f => GenericUnitProfunctor (Clown f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericUnitProfunctor (Joker f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericUnitProfunctor (FUN 'One)Defined in one-liner-2.1 · Generics.OneLiner.Classes(GenericUnitProfunctor p, GenericUnitProfunctor q) => GenericUnitProfunctor (Product p q)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Applicative f, GenericUnitProfunctor p) => GenericUnitProfunctor (Tannen f p)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Functor f, Applicative g, Profunctor p, GenericUnitProfunctor p) => GenericUnitProfunctor (Biff p f g)Defined in one-liner-2.1 · Generics.OneLiner.Classes
Instances13GenericProductProfunctor, …
Applicative f => GenericProductProfunctor (Zip f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericProductProfunctor (Kleisli f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericProductProfunctor CtorDefined in one-liner-2.1 · Generics.OneLiner.InternalGenericProductProfunctor TaggedDefined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericProductProfunctor (Star f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesFunctor f => GenericProductProfunctor (Costar f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericProductProfunctor (->)Defined in one-liner-2.1 · Generics.OneLiner.ClassesDivisible f => GenericProductProfunctor (Clown f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericProductProfunctor (Joker f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericProductProfunctor (FUN 'One)Defined in one-liner-2.1 · Generics.OneLiner.Classes(GenericProductProfunctor p, GenericProductProfunctor q) => GenericProductProfunctor (Product p q)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Applicative f, GenericProductProfunctor p) => GenericProductProfunctor (Tannen f p)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Functor f, Applicative g, Profunctor p, GenericProductProfunctor p) => GenericProductProfunctor (Biff p f g)Defined in one-liner-2.1 · Generics.OneLiner.Classes
Instances10GenericSumProfunctor, …
Alternative f => GenericSumProfunctor (Zip f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericSumProfunctor (Kleisli f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericSumProfunctor CtorDefined in one-liner-2.1 · Generics.OneLiner.InternalApplicative f => GenericSumProfunctor (Star f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericSumProfunctor (->)Defined in one-liner-2.1 · Generics.OneLiner.ClassesDecidable f => GenericSumProfunctor (Clown f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesAlternative f => GenericSumProfunctor (Joker f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericSumProfunctor (FUN 'One)Defined in one-liner-2.1 · Generics.OneLiner.Classes(GenericSumProfunctor p, GenericSumProfunctor q) => GenericSumProfunctor (Product p q)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Applicative f, GenericSumProfunctor p) => GenericSumProfunctor (Tannen f p)Defined in one-liner-2.1 · Generics.OneLiner.Classes
Instances10GenericEmptyProfunctor, …
Functor f => GenericEmptyProfunctor (Zip f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericEmptyProfunctor (Kleisli f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericEmptyProfunctor CtorDefined in one-liner-2.1 · Generics.OneLiner.InternalFunctor f => GenericEmptyProfunctor (Star f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericEmptyProfunctor (->)Defined in one-liner-2.1 · Generics.OneLiner.ClassesDecidable f => GenericEmptyProfunctor (Clown f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesAlternative f => GenericEmptyProfunctor (Joker f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericEmptyProfunctor (FUN 'One)Defined in one-liner-2.1 · Generics.OneLiner.Classes(GenericEmptyProfunctor p, GenericEmptyProfunctor q) => GenericEmptyProfunctor (Product p q)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Applicative f, GenericEmptyProfunctor p) => GenericEmptyProfunctor (Tannen f p)Defined in one-liner-2.1 · Generics.OneLiner.Classes
Methods
identity :: p c c
Instances10GenericConstantProfunctor, …
Alternative f => GenericConstantProfunctor (Zip f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesApplicative f => GenericConstantProfunctor (Kleisli f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericConstantProfunctor CtorDefined in one-liner-2.1 · Generics.OneLiner.InternalApplicative f => GenericConstantProfunctor (Star f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericConstantProfunctor (->)Defined in one-liner-2.1 · Generics.OneLiner.ClassesDecidable f => GenericConstantProfunctor (Clown f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesAlternative f => GenericConstantProfunctor (Joker f)Defined in one-liner-2.1 · Generics.OneLiner.ClassesGenericConstantProfunctor (FUN 'One)Defined in one-liner-2.1 · Generics.OneLiner.Classes(GenericConstantProfunctor p, GenericConstantProfunctor q) => GenericConstantProfunctor (Product p q)Defined in one-liner-2.1 · Generics.OneLiner.Classes(Applicative f, GenericConstantProfunctor p) => GenericConstantProfunctor (Tannen f p)Defined in one-liner-2.1 · Generics.OneLiner.Classes
Types
12 declarationstype Constraints1 (t :: Type -> Type) (c :: (Type -> Type) -> Constraint) = Constraints1 t t (D c)type Constraints01 (t :: Type -> Type) (c0 :: Type -> Constraint) (c1 :: (Type -> Type) -> Constraint) = Constraints01 t t (D c0) (D c1)Automatically apply a lifted function to a polymorphic argument as many times as possible.
A constraint `FunConstraint c t` is equivalent to the conjunction of
constraints `c s` for every argument type of t.
If r is not a function type:
c a :- FunConstraints c (a -> r)
(c a, c b) :- FunConstraints c (a -> b -> r)
(c a, c b, c d) :- FunConstraints c (a -> b -> d -> r)
Instances2FunConstraints
FunResult r ~ r => FunConstraints c rDefined in one-liner-2.1 · Generics.OneLiner.Internal(c a, FunConstraints c b) => FunConstraints c (a -> b)Defined in one-liner-2.1 · Generics.OneLiner.Internal
Instances1AnyType
AnyType aDefined in one-liner-2.1 · Generics.OneLiner.Internal.Unary