continuations-0.0.0.0: Continuations, CPS, co-functions, and combinators for working with them
Safe HaskellNone
LanguageHaskell2010

Data.Functor.Continuation

Description

Continuations, modelled as functions wrapped in a contravariant functor.

Synopsis

Continuations

newtype r ! a infixl 7 Source #

Continuations, represented as functions. Note that the type parameters are in the opposite order, making this type a Contravariant functor.

Constructors

K 

Fields

  • (!) :: a -> r
     

Instances

Instances details
ContravariantCPS r ((!) r) Source # 
Instance details

Defined in Data.Functor.Contravariant.CPS

Methods

(<#>) :: ((a' ~~ r) ~> a) -> (r ! a) -> r ! a' Source #

Contrapplicative r ((!) r) Source # 
Instance details

Defined in Data.Functor.Contravariant.Applicative

Methods

copure :: (b -> a) -> r ! ((a >- r) -~ b) Source #

Contrapply r ((!) r) Source # 
Instance details

Defined in Data.Functor.Contravariant.Applicative

Methods

coliftC2 :: ((((b >- r) -~ c) ~~ r) ~> a) -> (r ! a) -> (r ! b) -> r ! c Source #

(<&>) :: (r ! ((a >- r) -~ b)) -> (r ! a) -> r ! b Source #

Contravariant ((!) r) Source # 
Instance details

Defined in Data.Functor.Continuation

Methods

contramap :: (a -> b) -> (r ! b) -> r ! a #

(>$) :: b -> (r ! b) -> r ! a #

Representable ((!) r) Source # 
Instance details

Defined in Data.Functor.Continuation

Associated Types

type Rep ((!) r) #

Methods

tabulate :: (a -> Rep ((!) r)) -> r ! a #

index :: (r ! a) -> a -> Rep ((!) r) #

contramapWithRep :: (b -> Either a (Rep ((!) r))) -> (r ! a) -> r ! b #

Category (!) Source # 
Instance details

Defined in Data.Functor.Continuation

Methods

id :: forall (a :: k). a ! a #

(.) :: forall (b :: k) (c :: k) (a :: k). (b ! c) -> (a ! b) -> a ! c #

r ~ s => Adjunction ((!) r) ((!) s) Source # 
Instance details

Defined in Data.Functor.Continuation

Methods

unit :: a -> s ! (r ! a)

counit :: a -> r ! (s ! a)

leftAdjunct :: (b -> r ! a) -> a -> s ! b

rightAdjunct :: (a -> s ! b) -> b -> r ! a

type Rep ((!) r) Source # 
Instance details

Defined in Data.Functor.Continuation

type Rep ((!) r) = r

Contravariant

class Contravariant (f :: Type -> Type) where #

The class of contravariant functors.

Whereas in Haskell, one can think of a Functor as containing or producing values, a contravariant functor is a functor that can be thought of as consuming values.

As an example, consider the type of predicate functions a -> Bool. One such predicate might be negative x = x < 0, which classifies integers as to whether they are negative. However, given this predicate, we can re-use it in other situations, providing we have a way to map values to integers. For instance, we can use the negative predicate on a person's bank balance to work out if they are currently overdrawn:

newtype Predicate a = Predicate { getPredicate :: a -> Bool }

instance Contravariant Predicate where
  contramap f (Predicate p) = Predicate (p . f)
                                         |   `- First, map the input...
                                         `----- then apply the predicate.

overdrawn :: Predicate Person
overdrawn = contramap personBankBalance negative

Any instance should be subject to the following laws:

Identity
contramap id = id
Composition
contramap (g . f) = contramap f . contramap g

Note, that the second law follows from the free theorem of the type of contramap and the first law, so you need only check that the former condition holds.

Minimal complete definition

contramap

Methods

contramap :: (a -> b) -> f b -> f a #

(>$) :: b -> f b -> f a infixl 4 #

Replace all locations in the output with the same value. The default definition is contramap . const, but this may be overridden with a more efficient version.

Instances

Instances details
Contravariant Predicate

A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.

Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Predicate b -> Predicate a #

(>$) :: b -> Predicate b -> Predicate a #

Contravariant Comparison

A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function.

Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Comparison b -> Comparison a #

(>$) :: b -> Comparison b -> Comparison a #

Contravariant Equivalence

Equivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation.

Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Equivalence b -> Equivalence a #

(>$) :: b -> Equivalence b -> Equivalence a #

Contravariant (V1 :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> V1 b -> V1 a #

(>$) :: b -> V1 b -> V1 a #

Contravariant (U1 :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> U1 b -> U1 a #

(>$) :: b -> U1 b -> U1 a #

Contravariant (Op a) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a0 -> b) -> Op a b -> Op a a0 #

(>$) :: b -> Op a b -> Op a a0 #

Contravariant (Proxy :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Proxy b -> Proxy a #

(>$) :: b -> Proxy b -> Proxy a #

Contravariant ((!) r) Source # 
Instance details

Defined in Data.Functor.Continuation

Methods

contramap :: (a -> b) -> (r ! b) -> r ! a #

(>$) :: b -> (r ! b) -> r ! a #

Contravariant f => Contravariant (Rec1 f) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Rec1 f b -> Rec1 f a #

(>$) :: b -> Rec1 f b -> Rec1 f a #

Contravariant (Const a :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a0 -> b) -> Const a b -> Const a a0 #

(>$) :: b -> Const a b -> Const a a0 #

Contravariant f => Contravariant (Alt f) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Alt f b -> Alt f a #

(>$) :: b -> Alt f b -> Alt f a #

Contravariant m => Contravariant (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

contramap :: (a -> b) -> ErrorT e m b -> ErrorT e m a #

(>$) :: b -> ErrorT e m b -> ErrorT e m a #

Contravariant (K1 i c :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> K1 i c b -> K1 i c a #

(>$) :: b -> K1 i c b -> K1 i c a #

(Contravariant f, Contravariant g) => Contravariant (f :+: g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f :+: g) b -> (f :+: g) a #

(>$) :: b -> (f :+: g) b -> (f :+: g) a #

(Contravariant f, Contravariant g) => Contravariant (f :*: g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f :*: g) b -> (f :*: g) a #

(>$) :: b -> (f :*: g) b -> (f :*: g) a #

(Contravariant f, Contravariant g) => Contravariant (Product f g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Product f g b -> Product f g a #

(>$) :: b -> Product f g b -> Product f g a #

(Contravariant f, Contravariant g) => Contravariant (Sum f g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Sum f g b -> Sum f g a #

(>$) :: b -> Sum f g b -> Sum f g a #

Contravariant (Forget r a :: Type -> Type) 
Instance details

Defined in Data.Profunctor.Types

Methods

contramap :: (a0 -> b) -> Forget r a b -> Forget r a a0 #

(>$) :: b -> Forget r a b -> Forget r a a0 #

Contravariant f => Contravariant (Star f a) 
Instance details

Defined in Data.Profunctor.Types

Methods

contramap :: (a0 -> b) -> Star f a b -> Star f a a0 #

(>$) :: b -> Star f a b -> Star f a a0 #

Contravariant f => Contravariant (M1 i c f) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> M1 i c f b -> M1 i c f a #

(>$) :: b -> M1 i c f b -> M1 i c f a #

(Functor f, Contravariant g) => Contravariant (f :.: g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f :.: g) b -> (f :.: g) a #

(>$) :: b -> (f :.: g) b -> (f :.: g) a #

(Functor f, Contravariant g) => Contravariant (Compose f g) 
Instance details

Defined in Data.Functor.Contravariant

Methods

contramap :: (a -> b) -> Compose f g b -> Compose f g a #

(>$) :: b -> Compose f g b -> Compose f g a #

class Contravariant f => Representable (f :: Type -> Type) where #

Minimal complete definition

tabulate, index

Associated Types

type Rep (f :: Type -> Type) #

Methods

tabulate :: (a -> Rep f) -> f a #

index :: f a -> a -> Rep f #

contramapWithRep :: (b -> Either a (Rep f)) -> f a -> f b #

Instances

Instances details
Representable Predicate 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep Predicate #

Representable (U1 :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep U1 #

Methods

tabulate :: (a -> Rep U1) -> U1 a #

index :: U1 a -> a -> Rep U1 #

contramapWithRep :: (b -> Either a (Rep U1)) -> U1 a -> U1 b #

Representable (Op r) 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep (Op r) #

Methods

tabulate :: (a -> Rep (Op r)) -> Op r a #

index :: Op r a -> a -> Rep (Op r) #

contramapWithRep :: (b -> Either a (Rep (Op r))) -> Op r a -> Op r b #

Representable (Proxy :: Type -> Type) 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep Proxy #

Methods

tabulate :: (a -> Rep Proxy) -> Proxy a #

index :: Proxy a -> a -> Rep Proxy #

contramapWithRep :: (b -> Either a (Rep Proxy)) -> Proxy a -> Proxy b #

Representable ((!) r) Source # 
Instance details

Defined in Data.Functor.Continuation

Associated Types

type Rep ((!) r) #

Methods

tabulate :: (a -> Rep ((!) r)) -> r ! a #

index :: (r ! a) -> a -> Rep ((!) r) #

contramapWithRep :: (b -> Either a (Rep ((!) r))) -> (r ! a) -> r ! b #

(Representable f, Representable g) => Representable (f :*: g) 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep (f :*: g) #

Methods

tabulate :: (a -> Rep (f :*: g)) -> (f :*: g) a #

index :: (f :*: g) a -> a -> Rep (f :*: g) #

contramapWithRep :: (b -> Either a (Rep (f :*: g))) -> (f :*: g) a -> (f :*: g) b #

(Representable f, Representable g) => Representable (Product f g) 
Instance details

Defined in Data.Functor.Contravariant.Rep

Associated Types

type Rep (Product f g) #

Methods

tabulate :: (a -> Rep (Product f g)) -> Product f g a #

index :: Product f g a -> a -> Rep (Product f g) #

contramapWithRep :: (b -> Either a (Rep (Product f g))) -> Product f g a -> Product f g b #

Construction

idK :: a ! a Source #