conkin-1.0.2: Tools for functors from Hask^k to Hask

Safe HaskellNone
LanguageHaskell2010

Conkin

Description

The Conkin module defines tools for types of kind (k -> *) -> * (continuation kind types), treating them as functors from the category of types of kind k -> * (Hask^k) to the category of types of kind * (Hask).

It defines its own Functor, Applicative, Foldable, and Traversable classes, as continuation kind types are kind-incompatible with the homonymous classes in Prelude.

The Dispose type lifts a traditional functor to a continuation kind functor:

>>> :k Dispose Maybe 0
Dispose Maybe 0 :: (Nat -> *) -> *

While the Coyoneda type does the opposite.

>>> data OfSymbol a = OfSymbol (a "hello")
>>> :k OfSymbol
OfSymbol :: (Symbol -> *) -> *
>>> :k Coyoneda OfSymbol
Coyoneda OfSymbol :: * -> *

Two of the most useful functions provided by the module are align and apportion, as they allow you to transpose the composition of a traditional endofunctor and a continuation kind functor.

>>> rows = zipWith (\ch ix -> Pair (Identity ch, Identity ix)) "abc" [0..2]
>>> rows
[ Pair { getPair = ( Identity 'a' , Identity 0 ) }
, Pair { getPair = ( Identity 'b' , Identity 1 ) }
, Pair { getPair = ( Identity 'c' , Identity 2 ) }
]
>>> cols = align rows
>>> cols
Pair { getPair = ( "abc" , [ 0 , 1 , 2 ] ) }
>>> apportion cols
[ Pair { getPair = ( Identity 'a' , Identity 0 ) }
, Pair { getPair = ( Identity 'a' , Identity 1 ) }
, Pair { getPair = ( Identity 'a' , Identity 2 ) }
, Pair { getPair = ( Identity 'b' , Identity 0 ) }
, Pair { getPair = ( Identity 'b' , Identity 1 ) }
, Pair { getPair = ( Identity 'b' , Identity 2 ) }
, Pair { getPair = ( Identity 'c' , Identity 0 ) }
, Pair { getPair = ( Identity 'c' , Identity 1 ) }
, Pair { getPair = ( Identity 'c' , Identity 2 ) }
]
>>> apportion $ fmap ZipList cols
ZipList
  { getZipList = 
      [ Pair { getPair = ( Identity 'a' , Identity 0 ) }
      , Pair { getPair = ( Identity 'b' , Identity 1 ) }
      , Pair { getPair = ( Identity 'c' , Identity 2 ) }
      ]
  }

There's also convenience types for Products and Coproducts of continuation kind functors, as well as for Tuples and Tagged unions of arbitrary types.

Synopsis

Documentation

class Functor f where Source #

A functor from Hask^k to Hask, an analogue of Functor for kind (k -> *) -> *

Minimal complete definition

fmap

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Instances

Functor k (Pure k x) Source # 

Methods

fmap :: (forall a. a a -> b a) -> f a -> f b Source #

Functor k (Const (k -> *) a) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Functor k (Tagged k xs) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Functor k (Tuple k xs) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Functor k (Pair k x0 x1) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Functor f => Functor k (Dispose k f x) Source # 

Methods

fmap :: (forall a. a a -> b a) -> f a -> f b Source #

(Functor f, Functor k g) => Functor k (Compose (k -> *) * f g) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Functor i f, Functor j g) => Functor (Either i j) (Coproduct j i f g) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Functor i f, Functor j g) => Functor (i, j) (Product j i f g) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(<$>) :: Functor f => (forall x. a x -> b x) -> f a -> f b infixl 4 Source #

An analogue of <$> for use with Conkin's Functor

class Functor f => Applicative f where Source #

An analogue of Applicative for kind (k -> *) -> *

Minimal complete definition

pure, (<*>)

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f (a ~> b) -> f a -> f b infixl 4 Source #

Instances

Applicative k (Pure k x) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Pure k x ~> a) b) -> f a -> f b Source #

Monoid m => Applicative k (Const (k -> *) m) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Const (k -> *) m ~> a) b) -> f a -> f b Source #

Applicative k (Tuple k xs) => Applicative k (Tuple k ((:) k x xs)) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Tuple k ((k ': x) xs) ~> a) b) -> f a -> f b Source #

Applicative k (Tuple k ([] k)) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Tuple k [k] ~> a) b) -> f a -> f b Source #

Applicative k (Pair k x0 x1) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Pair k x0 x1 ~> a) b) -> f a -> f b Source #

Applicative f => Applicative k (Dispose k f x) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Dispose k f x ~> a) b) -> f a -> f b Source #

(Applicative f, Applicative k g) => Applicative k (Compose (k -> *) * f g) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Compose (k -> *) * f g ~> a) b) -> f a -> f b Source #

(Applicative i f, Applicative j g) => Applicative (Either i j) (Coproduct j i f g) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Coproduct j i f g ~> a) b) -> f a -> f b Source #

(Applicative i f, Applicative j g) => Applicative (i, j) (Product j i f g) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Product j i f g ~> a) b) -> f a -> f b Source #

newtype (a ~> b) x infixr 0 Source #

arrows in Hask^k have type a ~> b :: k -> *

Constructors

Arrow 

Fields

liftA2 :: Applicative f => (forall x. a x -> b x -> c x) -> f a -> f b -> f c Source #

An analogue of liftA2 for use with Conkin's Applicative

liftA3 :: Applicative f => (forall x. a x -> b x -> c x -> d x) -> f a -> f b -> f c -> f d Source #

An analogue of liftA3 for use with Conkin's Applicative

liftA4 :: Applicative f => (forall x. a x -> b x -> c x -> d x -> e x) -> f a -> f b -> f c -> f d -> f e Source #

An extension of liftA3 to functions of four arguments

class Foldable t where Source #

An analogue of Foldable for kind (k -> *) -> *

Minimal complete definition

foldr | foldMap

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Instances

Foldable k (Pure k x) Source # 

Methods

foldr :: (forall a. a a -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall a. a a -> m) -> t a -> m Source #

Foldable k (Const (k -> *) m) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Foldable k (Tagged k xs) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Foldable k (Tuple k xs) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Foldable k (Pair k x0 x1) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Foldable t => Foldable k (Dispose k t x) Source # 

Methods

foldr :: (forall a. a a -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall a. a a -> m) -> t a -> m Source #

(Foldable f, Foldable k g) => Foldable k (Compose (k -> *) * f g) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

(Foldable i f, Foldable j g) => Foldable (Either i j) (Coproduct j i f g) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

(Foldable i f, Foldable j g) => Foldable (i, j) (Product j i f g) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

class (Foldable t, Functor t) => Traversable t where Source #

An analogue of Traversable for kind (k -> *) -> *

Minimal complete definition

traverse | sequenceA

Methods

traverse :: forall f a b. Applicative f => (forall x. a x -> f (b x)) -> t a -> f (Compose t (Flip b)) Source #

sequenceA :: forall f a. Applicative f => t (Compose f a) -> f (Compose t (Flip a)) Source #

Instances

Traversable i (Pure i x) Source # 

Methods

traverse :: Applicative j f => (forall a. a a -> f (b a)) -> t a -> f (Compose j (Pure i x -> *) t (Flip j (Pure i x) b)) Source #

sequenceA :: Applicative j f => t (Compose (Pure i x) (j -> *) f a) -> f (Compose j (Pure i x -> *) t (Flip j (Pure i x) a)) Source #

Traversable i (Const (i -> *) m) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Const (i -> *) m -> *) t (Flip j (Const (i -> *) m) b)) Source #

sequenceA :: Applicative j f => t (Compose (Const (i -> *) m) (j -> *) f a) -> f (Compose j (Const (i -> *) m -> *) t (Flip j (Const (i -> *) m) a)) Source #

Traversable i (Tagged i xs) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Tagged i xs -> *) t (Flip j (Tagged i xs) b)) Source #

sequenceA :: Applicative j f => t (Compose (Tagged i xs) (j -> *) f a) -> f (Compose j (Tagged i xs -> *) t (Flip j (Tagged i xs) a)) Source #

Traversable i (Tuple i xs) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Tuple i xs -> *) t (Flip j (Tuple i xs) b)) Source #

sequenceA :: Applicative j f => t (Compose (Tuple i xs) (j -> *) f a) -> f (Compose j (Tuple i xs -> *) t (Flip j (Tuple i xs) a)) Source #

Traversable i (Pair i x0 x1) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Pair i x0 x1 -> *) t (Flip j (Pair i x0 x1) b)) Source #

sequenceA :: Applicative j f => t (Compose (Pair i x0 x1) (j -> *) f a) -> f (Compose j (Pair i x0 x1 -> *) t (Flip j (Pair i x0 x1) a)) Source #

Traversable t => Traversable i (Dispose i t x) Source # 

Methods

traverse :: Applicative j f => (forall a. a a -> f (b a)) -> t a -> f (Compose j (Dispose i t x -> *) t (Flip j (Dispose i t x) b)) Source #

sequenceA :: Applicative j f => t (Compose (Dispose i t x) (j -> *) f a) -> f (Compose j (Dispose i t x -> *) t (Flip j (Dispose i t x) a)) Source #

(Traversable f, Traversable i g) => Traversable i (Compose (i -> *) * f g) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Compose (i -> *) * f g -> *) t (Flip j (Compose (i -> *) * f g) b)) Source #

sequenceA :: Applicative j f => t (Compose (Compose (i -> *) * f g) (j -> *) f a) -> f (Compose j (Compose (i -> *) * f g -> *) t (Flip j (Compose (i -> *) * f g) a)) Source #

(Traversable i f, Traversable j g) => Traversable (Either i j) (Coproduct j i f g) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Coproduct j i f g -> *) t (Flip j (Coproduct j i f g) b)) Source #

sequenceA :: Applicative j f => t (Compose (Coproduct j i f g) (j -> *) f a) -> f (Compose j (Coproduct j i f g -> *) t (Flip j (Coproduct j i f g) a)) Source #

(Traversable i f, Traversable j g) => Traversable (i, j) (Product j i f g) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Product j i f g -> *) t (Flip j (Product j i f g) b)) Source #

sequenceA :: Applicative j f => t (Compose (Product j i f g) (j -> *) f a) -> f (Compose j (Product j i f g -> *) t (Flip j (Product j i f g) a)) Source #

traverse' :: (Traversable t, Applicative f) => (forall x. a x -> f (Flip b x)) -> t a -> f (Compose t b) Source #

version of traverse that unflips the inner type

sequenceA' :: (Traversable t, Applicative f) => t (Compose f (Flip a)) -> f (Compose t a) Source #

version of sequenceA that unflips the inner type

liftT1 :: Applicative g => (forall h. h w -> f h) -> Compose g a w -> g (Compose f (Flip a)) Source #

sequenceA helper for single-parameter constructors

>>> :{
data OfOne a = OfOne (a Int)
instance Functor OfOne where
  fmap h (OfOne a) = OfOne (h a)
instance Applicative OfOne where
  pure = OfOne
  OfOne f <*> OfOne a = OfOne (f ~$~ a)
instance Foldable OfOne where
  foldMap h (OfOne a) = h a
instance Traversable OfOne where
  sequenceA (OfOne fa) = liftT1 OfOne fa
:}

liftT2 :: Applicative g => (forall h. h w -> h x -> f h) -> Compose g a w -> Compose g a x -> g (Compose f (Flip a)) Source #

sequenceA helper for two-parameter constructors

>>> :{
data OfTwo a = OfTwo (a Int) (a Char)
instance Functor OfTwo where
  fmap h (OfTwo ai ac) = OfTwo (h ai) (h ac)
instance Applicative OfTwo where
  pure a = OfTwo a a
  OfTwo fi fc <*> OfTwo ai ac = OfTwo (fi ~$~ ai) (fc ~$~ ac)
instance Foldable OfTwo where
  foldMap h (OfTwo ai ac) = h ai <> h ac
instance Traversable OfTwo where
  sequenceA (OfTwo fai fac) = liftT2 OfTwo fai fac
:}

liftT3 :: Applicative g => (forall h. h w -> h x -> h y -> f h) -> Compose g a w -> Compose g a x -> Compose g a y -> g (Compose f (Flip a)) Source #

sequenceA helper for three-parameter constructors

>>> :{
data OfThree a = OfThree (a Int) (a Char) (a Bool)
instance Functor OfThree where
  fmap h (OfThree ai ac ab) = OfThree (h ai) (h ac) (h ab)
instance Applicative OfThree where
  pure a = OfThree a a a
  OfThree fi fc fb <*> OfThree ai ac ab = OfThree (fi ~$~ ai) (fc ~$~ ac) (fb ~$~ ab)
instance Foldable OfThree where
  foldMap h (OfThree ai ac ab) = h ai <> h ac <> h ab
instance Traversable OfThree where
  sequenceA (OfThree fai fac fab) = liftT3 OfThree fai fac fab
:}

liftT4 :: Applicative g => (forall h. h w -> h x -> h y -> h z -> f h) -> Compose g a w -> Compose g a x -> Compose g a y -> Compose g a z -> g (Compose f (Flip a)) Source #

sequenceA helper for four-parameter constructors

>>> :{
data OfFour a = OfFour (a Int) (a Char) (a Bool) (a Double)
instance Functor OfFour where
  fmap h (OfFour ai ac ab ad) = OfFour (h ai) (h ac) (h ab) (h ad)
instance Applicative OfFour where
  pure a = OfFour a a a a
  OfFour fi fc fb fd <*> OfFour ai ac ab ad = OfFour (fi ~$~ ai) (fc ~$~ ac) (fb ~$~ ab) (fd ~$~ ad)
instance Foldable OfFour where
  foldMap h (OfFour ai ac ab ad) = h ai <> h ac <> h ab <> h ad
instance Traversable OfFour where
  sequenceA (OfFour fai fac fab fad) = liftT4 OfFour fai fac fab fad
:}

align :: (Traversable f, Applicative g) => f (g Identity) -> g f Source #

Loosely, align transforms an array of structures into a structure of arrays, if by "array" one means an arbitrary collection type.

>>> rows = zipWith (\ch ix -> Pair (Identity ch, Identity ix)) "abc" [0..2]
>>> rows
[ Pair { getPair = ( Identity 'a' , Identity 0 ) }
, Pair { getPair = ( Identity 'b' , Identity 1 ) }
, Pair { getPair = ( Identity 'c' , Identity 2 ) }
]
>>> align rows
Pair { getPair = ( "abc" , [ 0 , 1 , 2 ] ) }

apportion :: (Applicative f, Traversable g) => g f -> f (g Identity) Source #

Loosely, apportion transforms a structure of arrays into an array of structures, if by "array" one means an arbitrary collection type.

Depending on the collection's Applicative instance, this may or may not be the inverse of align.

>>> cols = Pair { getPair = ( "abc" , [ 0 , 1 , 2 ] ) }
>>> apportion cols
[ Pair { getPair = ( Identity 'a' , Identity 0 ) }
, Pair { getPair = ( Identity 'a' , Identity 1 ) }
, Pair { getPair = ( Identity 'a' , Identity 2 ) }
, Pair { getPair = ( Identity 'b' , Identity 0 ) }
, Pair { getPair = ( Identity 'b' , Identity 1 ) }
, Pair { getPair = ( Identity 'b' , Identity 2 ) }
, Pair { getPair = ( Identity 'c' , Identity 0 ) }
, Pair { getPair = ( Identity 'c' , Identity 1 ) }
, Pair { getPair = ( Identity 'c' , Identity 2 ) }
]
>>> apportion $ fmap ZipList cols
ZipList
  { getZipList = 
      [ Pair { getPair = ( Identity 'a' , Identity 0 ) }
      , Pair { getPair = ( Identity 'b' , Identity 1 ) }
      , Pair { getPair = ( Identity 'c' , Identity 2 ) }
      ]
  }

newtype Dispose f x a Source #

If f is a functor from Hask to Hask, then, forall (x :: k). Dispose f x is a functor from Hask^k to Hask

The name comes from the isomorphism Dispose f ~ Flip (Compose f) :: k -> (k -> *) -> *, as a pun off the latin prefixes "com-", meaning together, and "dis-", meaning apart.

Constructors

Dispose 

Fields

Instances

Traversable t => Traversable i (Dispose i t x) Source # 

Methods

traverse :: Applicative j f => (forall a. a a -> f (b a)) -> t a -> f (Compose j (Dispose i t x -> *) t (Flip j (Dispose i t x) b)) Source #

sequenceA :: Applicative j f => t (Compose (Dispose i t x) (j -> *) f a) -> f (Compose j (Dispose i t x -> *) t (Flip j (Dispose i t x) a)) Source #

Foldable t => Foldable k (Dispose k t x) Source # 

Methods

foldr :: (forall a. a a -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall a. a a -> m) -> t a -> m Source #

Applicative f => Applicative k (Dispose k f x) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Dispose k f x ~> a) b) -> f a -> f b Source #

Functor f => Functor k (Dispose k f x) Source # 

Methods

fmap :: (forall a. a a -> b a) -> f a -> f b Source #

Eq (f (a x)) => Eq (Dispose k f x a) Source # 

Methods

(==) :: Dispose k f x a -> Dispose k f x a -> Bool #

(/=) :: Dispose k f x a -> Dispose k f x a -> Bool #

Ord (f (a x)) => Ord (Dispose k f x a) Source # 

Methods

compare :: Dispose k f x a -> Dispose k f x a -> Ordering #

(<) :: Dispose k f x a -> Dispose k f x a -> Bool #

(<=) :: Dispose k f x a -> Dispose k f x a -> Bool #

(>) :: Dispose k f x a -> Dispose k f x a -> Bool #

(>=) :: Dispose k f x a -> Dispose k f x a -> Bool #

max :: Dispose k f x a -> Dispose k f x a -> Dispose k f x a #

min :: Dispose k f x a -> Dispose k f x a -> Dispose k f x a #

Show (f (a x)) => Show (Dispose k f x a) Source # 

Methods

showsPrec :: Int -> Dispose k f x a -> ShowS #

show :: Dispose k f x a -> String #

showList :: [Dispose k f x a] -> ShowS #

data Coyoneda t u where Source #

If t is a functor from Hask^k to Hask, then Coyoneda t is a functor from Hask to Hask.

It's very similar to the Coyoneda from the kan-extensions package, differing only in kind, and Coyoneda t a is isomorphic to t (Const a) for any Functor.

Constructors

Coyoneda :: (forall x. a x -> u) -> t a -> Coyoneda t u 

Instances

Functor (Coyoneda k t) Source # 

Methods

fmap :: (a -> b) -> Coyoneda k t a -> Coyoneda k t b #

(<$) :: a -> Coyoneda k t b -> Coyoneda k t a #

Applicative k t => Applicative (Coyoneda k t) Source # 

Methods

pure :: a -> Coyoneda k t a #

(<*>) :: Coyoneda k t (a -> b) -> Coyoneda k t a -> Coyoneda k t b #

(*>) :: Coyoneda k t a -> Coyoneda k t b -> Coyoneda k t b #

(<*) :: Coyoneda k t a -> Coyoneda k t b -> Coyoneda k t a #

Foldable k t => Foldable (Coyoneda k t) Source # 

Methods

fold :: Monoid m => Coyoneda k t m -> m #

foldMap :: Monoid m => (a -> m) -> Coyoneda k t a -> m #

foldr :: (a -> b -> b) -> b -> Coyoneda k t a -> b #

foldr' :: (a -> b -> b) -> b -> Coyoneda k t a -> b #

foldl :: (b -> a -> b) -> b -> Coyoneda k t a -> b #

foldl' :: (b -> a -> b) -> b -> Coyoneda k t a -> b #

foldr1 :: (a -> a -> a) -> Coyoneda k t a -> a #

foldl1 :: (a -> a -> a) -> Coyoneda k t a -> a #

toList :: Coyoneda k t a -> [a] #

null :: Coyoneda k t a -> Bool #

length :: Coyoneda k t a -> Int #

elem :: Eq a => a -> Coyoneda k t a -> Bool #

maximum :: Ord a => Coyoneda k t a -> a #

minimum :: Ord a => Coyoneda k t a -> a #

sum :: Num a => Coyoneda k t a -> a #

product :: Num a => Coyoneda k t a -> a #

Traversable k t => Traversable (Coyoneda k t) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Coyoneda k t a -> f (Coyoneda k t b) #

sequenceA :: Applicative f => Coyoneda k t (f a) -> f (Coyoneda k t a) #

mapM :: Monad m => (a -> m b) -> Coyoneda k t a -> m (Coyoneda k t b) #

sequence :: Monad m => Coyoneda k t (m a) -> m (Coyoneda k t a) #

getCoyoneda :: Functor t => Coyoneda t a -> t (Const a) Source #

convert a functor from its Coyoneda representation

toCoyoneda :: t (Const a) -> Coyoneda t a Source #

convert a functor to its Coyoneda representation

newtype Product f g a Source #

The product of two continuation kind functors is a continuation kind functor.

>>> data A z where A :: Int -> [x] -> [y] -> A '(x,y)
>>> data B z where B :: [(x,y)] -> B '(x,y)
>>> foo = Product . Pure . Compose . Pure . Curry $ A 0 "abc" [True, False]
>>> :t foo
foo :: Product (Pure Char) (Pure Bool) A
>>> a2b :: A z -> B z ; a2b (A _ xs ys) = B $ zip xs ys
>>> :t fmap a2b foo
fmap a2b foo :: Product (Pure Char) (Pure Bool) B

Constructors

Product 

Fields

Instances

(Traversable i f, Traversable j g) => Traversable (i, j) (Product j i f g) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Product j i f g -> *) t (Flip j (Product j i f g) b)) Source #

sequenceA :: Applicative j f => t (Compose (Product j i f g) (j -> *) f a) -> f (Compose j (Product j i f g -> *) t (Flip j (Product j i f g) a)) Source #

(Foldable i f, Foldable j g) => Foldable (i, j) (Product j i f g) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

(Applicative i f, Applicative j g) => Applicative (i, j) (Product j i f g) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Product j i f g ~> a) b) -> f a -> f b Source #

(Functor i f, Functor j g) => Functor (i, j) (Product j i f g) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

Eq (f (Compose i (j -> *) g (Curry i j a))) => Eq (Product j i f g a) Source # 

Methods

(==) :: Product j i f g a -> Product j i f g a -> Bool #

(/=) :: Product j i f g a -> Product j i f g a -> Bool #

Ord (f (Compose i (j -> *) g (Curry i j a))) => Ord (Product j i f g a) Source # 

Methods

compare :: Product j i f g a -> Product j i f g a -> Ordering #

(<) :: Product j i f g a -> Product j i f g a -> Bool #

(<=) :: Product j i f g a -> Product j i f g a -> Bool #

(>) :: Product j i f g a -> Product j i f g a -> Bool #

(>=) :: Product j i f g a -> Product j i f g a -> Bool #

max :: Product j i f g a -> Product j i f g a -> Product j i f g a #

min :: Product j i f g a -> Product j i f g a -> Product j i f g a #

Show (f (Compose i (j -> *) g (Curry i j a))) => Show (Product j i f g a) Source # 

Methods

showsPrec :: Int -> Product j i f g a -> ShowS #

show :: Product j i f g a -> String #

showList :: [Product j i f g a] -> ShowS #

toProduct :: (Functor f, Functor g) => (forall x y. a x y -> b '(x, y)) -> f (Compose g a) -> Product f g b Source #

helper to make a Product when the inner type is already curried.

>>> comma = Pure . Compose . Pure $ ('a', True)
>>> :t comma
comma :: Pure Char (Compose (Pure Bool) (,))
>>> :t toProduct UncurryStrict comma
toProduct UncurryStrict comma
  :: Product (Pure Char) (Pure Bool) (Uncurry (,))

fromProduct :: (Functor f, Functor g) => (forall x y. b '(x, y) -> a x y) -> Product f g b -> f (Compose g a) Source #

helper to unwrap a Product when the inner type is already curried.

>>> comma' = toProduct UncurryStrict . Pure . Compose . Pure $ ('a', True)
>>> :t comma'
comma' :: Product (Pure Char) (Pure Bool) (Uncurry (,))
>>> :t getProduct comma'
getProduct comma'
  :: Pure Char (Compose (Pure Bool) (Curry (Uncurry (,))))
>>> :t fromProduct getUncurryStrict comma'
fromProduct getUncurryStrict comma'
  :: Pure Char (Compose (Pure Bool) (,))

newtype Coproduct f g a Source #

The coproduct of two continuation kind functors is a continuation kind functor.

>>> data A z where { AL :: i -> A ('Left i) ; AR :: j -> A ('Right j) }
>>> data B z where { BL :: i -> i -> B ('Left i) ; BR :: B ('Right j) }
>>> bar = Coproduct (Pure . Compose $ AL True, Pure . Compose $ AR 'a')
>>> :t bar
bar :: Coproduct (Pure Bool) (Pure Char) A
>>> a2b :: A z -> B z ; a2b (AL i) = BL i i ; a2b (AR _) = BR
>>> :t fmap a2b bar
fmap a2b bar :: Coproduct (Pure Bool) (Pure Char) B

Constructors

Coproduct 

Fields

Instances

(Traversable i f, Traversable j g) => Traversable (Either i j) (Coproduct j i f g) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Coproduct j i f g -> *) t (Flip j (Coproduct j i f g) b)) Source #

sequenceA :: Applicative j f => t (Compose (Coproduct j i f g) (j -> *) f a) -> f (Compose j (Coproduct j i f g -> *) t (Flip j (Coproduct j i f g) a)) Source #

(Foldable i f, Foldable j g) => Foldable (Either i j) (Coproduct j i f g) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

(Applicative i f, Applicative j g) => Applicative (Either i j) (Coproduct j i f g) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Coproduct j i f g ~> a) b) -> f a -> f b Source #

(Functor i f, Functor j g) => Functor (Either i j) (Coproduct j i f g) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Eq (f (Compose i (Either i j) a (Left i j))), Eq (g (Compose j (Either i j) a (Right i j)))) => Eq (Coproduct j i f g a) Source # 

Methods

(==) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

(/=) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

(Ord (f (Compose i (Either i j) a (Left i j))), Ord (g (Compose j (Either i j) a (Right i j)))) => Ord (Coproduct j i f g a) Source # 

Methods

compare :: Coproduct j i f g a -> Coproduct j i f g a -> Ordering #

(<) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

(<=) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

(>) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

(>=) :: Coproduct j i f g a -> Coproduct j i f g a -> Bool #

max :: Coproduct j i f g a -> Coproduct j i f g a -> Coproduct j i f g a #

min :: Coproduct j i f g a -> Coproduct j i f g a -> Coproduct j i f g a #

(Show (f (Compose i (Either i j) a (Left i j))), Show (g (Compose j (Either i j) a (Right i j)))) => Show (Coproduct j i f g a) Source # 

Methods

showsPrec :: Int -> Coproduct j i f g a -> ShowS #

show :: Coproduct j i f g a -> String #

showList :: [Coproduct j i f g a] -> ShowS #

newtype Pair x0 x1 a Source #

A continuation kind functor for pairs.

>>> :t Pair (Identity True, Identity 'a')
Pair (Identity True, Identity 'a') :: Pair Bool Char Identity

Constructors

Pair 

Fields

Instances

Traversable i (Pair i x0 x1) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Pair i x0 x1 -> *) t (Flip j (Pair i x0 x1) b)) Source #

sequenceA :: Applicative j f => t (Compose (Pair i x0 x1) (j -> *) f a) -> f (Compose j (Pair i x0 x1 -> *) t (Flip j (Pair i x0 x1) a)) Source #

Foldable k (Pair k x0 x1) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Applicative k (Pair k x0 x1) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Pair k x0 x1 ~> a) b) -> f a -> f b Source #

Functor k (Pair k x0 x1) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Eq (a x1), Eq (a x0)) => Eq (Pair k x0 x1 a) Source # 

Methods

(==) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

(/=) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

(Ord (a x1), Ord (a x0)) => Ord (Pair k x0 x1 a) Source # 

Methods

compare :: Pair k x0 x1 a -> Pair k x0 x1 a -> Ordering #

(<) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

(<=) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

(>) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

(>=) :: Pair k x0 x1 a -> Pair k x0 x1 a -> Bool #

max :: Pair k x0 x1 a -> Pair k x0 x1 a -> Pair k x0 x1 a #

min :: Pair k x0 x1 a -> Pair k x0 x1 a -> Pair k x0 x1 a #

(Show (a x1), Show (a x0)) => Show (Pair k x0 x1 a) Source # 

Methods

showsPrec :: Int -> Pair k x0 x1 a -> ShowS #

show :: Pair k x0 x1 a -> String #

showList :: [Pair k x0 x1 a] -> ShowS #

data Tuple xs a where Source #

A continuation kind functor for tuples of arbitrary length.

>>> :t Identity True `Cons` Identity 'a' `Cons` Nil
Identity True `Cons` Identity 'a' `Cons` Nil
  :: Tuple '[Bool, Char] Identity

Constructors

Nil :: Tuple '[] a 
Cons :: a x -> !(Tuple xs a) -> Tuple (x ': xs) a infixr 5 

Instances

Traversable i (Tuple i xs) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Tuple i xs -> *) t (Flip j (Tuple i xs) b)) Source #

sequenceA :: Applicative j f => t (Compose (Tuple i xs) (j -> *) f a) -> f (Compose j (Tuple i xs -> *) t (Flip j (Tuple i xs) a)) Source #

Foldable k (Tuple k xs) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Applicative k (Tuple k xs) => Applicative k (Tuple k ((:) k x xs)) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Tuple k ((k ': x) xs) ~> a) b) -> f a -> f b Source #

Applicative k (Tuple k ([] k)) Source # 

Methods

pure :: (forall x. a x) -> f a Source #

(<*>) :: f ((Tuple k [k] ~> a) b) -> f a -> f b Source #

Functor k (Tuple k xs) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Eq (a x), Eq (Tuple k xs a)) => Eq (Tuple k ((:) k x xs) a) Source # 

Methods

(==) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

(/=) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

Eq (Tuple k ([] k) a) Source # 

Methods

(==) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

(/=) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

(Ord (a x), Ord (Tuple k xs a)) => Ord (Tuple k ((:) k x xs) a) Source # 

Methods

compare :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Ordering #

(<) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

(<=) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

(>) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

(>=) :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Bool #

max :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a #

min :: Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a -> Tuple k ((k ': x) xs) a #

Ord (Tuple k ([] k) a) Source # 

Methods

compare :: Tuple k [k] a -> Tuple k [k] a -> Ordering #

(<) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

(<=) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

(>) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

(>=) :: Tuple k [k] a -> Tuple k [k] a -> Bool #

max :: Tuple k [k] a -> Tuple k [k] a -> Tuple k [k] a #

min :: Tuple k [k] a -> Tuple k [k] a -> Tuple k [k] a #

(Show (a x), Show (Tuple k xs a)) => Show (Tuple k ((:) k x xs) a) Source # 

Methods

showsPrec :: Int -> Tuple k ((k ': x) xs) a -> ShowS #

show :: Tuple k ((k ': x) xs) a -> String #

showList :: [Tuple k ((k ': x) xs) a] -> ShowS #

Show (Tuple k ([] k) a) Source # 

Methods

showsPrec :: Int -> Tuple k [k] a -> ShowS #

show :: Tuple k [k] a -> String #

showList :: [Tuple k [k] a] -> ShowS #

data Tagged xs a where Source #

A continuation kind functor for tagged unions

>>> :t [ Here (Identity True), There $ Here (Identity 'a') ]
[ Here (Identity True), There $ Here (Identity 'a') ]
  :: [Tagged (Bool : Char : xs) Identity]

Constructors

Here :: a x -> Tagged (x ': xs) a 
There :: !(Tagged xs a) -> Tagged (x ': xs) a 

Instances

Traversable i (Tagged i xs) Source # 

Methods

traverse :: Applicative j f => (forall x. a x -> f (b x)) -> t a -> f (Compose j (Tagged i xs -> *) t (Flip j (Tagged i xs) b)) Source #

sequenceA :: Applicative j f => t (Compose (Tagged i xs) (j -> *) f a) -> f (Compose j (Tagged i xs -> *) t (Flip j (Tagged i xs) a)) Source #

Foldable k (Tagged k xs) Source # 

Methods

foldr :: (forall x. a x -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall x. a x -> m) -> t a -> m Source #

Functor k (Tagged k xs) Source # 

Methods

fmap :: (forall x. a x -> b x) -> f a -> f b Source #

(Eq (a x), Eq (Tagged k xs a)) => Eq (Tagged k ((:) k x xs) a) Source # 

Methods

(==) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

(/=) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

Eq (Tagged k ([] k) a) Source # 

Methods

(==) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

(/=) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

(Ord (a x), Ord (Tagged k xs a)) => Ord (Tagged k ((:) k x xs) a) Source # 

Methods

compare :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Ordering #

(<) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

(<=) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

(>) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

(>=) :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Bool #

max :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a #

min :: Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a -> Tagged k ((k ': x) xs) a #

Ord (Tagged k ([] k) a) Source # 

Methods

compare :: Tagged k [k] a -> Tagged k [k] a -> Ordering #

(<) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

(<=) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

(>) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

(>=) :: Tagged k [k] a -> Tagged k [k] a -> Bool #

max :: Tagged k [k] a -> Tagged k [k] a -> Tagged k [k] a #

min :: Tagged k [k] a -> Tagged k [k] a -> Tagged k [k] a #

(Show (a x), Show (Tagged k xs a)) => Show (Tagged k ((:) k x xs) a) Source # 

Methods

showsPrec :: Int -> Tagged k ((k ': x) xs) a -> ShowS #

show :: Tagged k ((k ': x) xs) a -> String #

showList :: [Tagged k ((k ': x) xs) a] -> ShowS #

Show (Tagged k ([] k) a) Source # 

Methods

showsPrec :: Int -> Tagged k [k] a -> ShowS #

show :: Tagged k [k] a -> String #

showList :: [Tagged k [k] a] -> ShowS #

newtype Flip a y x Source #

a type-level version of flip, it's used in the definition of traverse and sequenceA as a way to reverse the order in which parameters are passed.

Flip (Flip a) is isomorphic to Identity a

>>> :t Flip . Flip
Flip . Flip :: a y x -> Flip (Flip a) y x
>>> :t getFlip . getFlip
getFlip . getFlip :: Flip (Flip a) x y -> a x y

Constructors

Flip 

Fields

Instances

Eq (a x y) => Eq (Flip j i a y x) Source # 

Methods

(==) :: Flip j i a y x -> Flip j i a y x -> Bool #

(/=) :: Flip j i a y x -> Flip j i a y x -> Bool #

Ord (a x y) => Ord (Flip j i a y x) Source # 

Methods

compare :: Flip j i a y x -> Flip j i a y x -> Ordering #

(<) :: Flip j i a y x -> Flip j i a y x -> Bool #

(<=) :: Flip j i a y x -> Flip j i a y x -> Bool #

(>) :: Flip j i a y x -> Flip j i a y x -> Bool #

(>=) :: Flip j i a y x -> Flip j i a y x -> Bool #

max :: Flip j i a y x -> Flip j i a y x -> Flip j i a y x #

min :: Flip j i a y x -> Flip j i a y x -> Flip j i a y x #

Show (a x y) => Show (Flip j i a y x) Source # 

Methods

showsPrec :: Int -> Flip j i a y x -> ShowS #

show :: Flip j i a y x -> String #

showList :: [Flip j i a y x] -> ShowS #

newtype Curry a x y Source #

a type-level version of curry, it's used to convert between types of kind (i,j) -> * and types of kind i -> j -> *

Constructors

Curry 

Fields

Instances

Eq (a ((,) i j x y)) => Eq (Curry i j a x y) Source # 

Methods

(==) :: Curry i j a x y -> Curry i j a x y -> Bool #

(/=) :: Curry i j a x y -> Curry i j a x y -> Bool #

Ord (a ((,) i j x y)) => Ord (Curry i j a x y) Source # 

Methods

compare :: Curry i j a x y -> Curry i j a x y -> Ordering #

(<) :: Curry i j a x y -> Curry i j a x y -> Bool #

(<=) :: Curry i j a x y -> Curry i j a x y -> Bool #

(>) :: Curry i j a x y -> Curry i j a x y -> Bool #

(>=) :: Curry i j a x y -> Curry i j a x y -> Bool #

max :: Curry i j a x y -> Curry i j a x y -> Curry i j a x y #

min :: Curry i j a x y -> Curry i j a x y -> Curry i j a x y #

Show (a ((,) i j x y)) => Show (Curry i j a x y) Source # 

Methods

showsPrec :: Int -> Curry i j a x y -> ShowS #

show :: Curry i j a x y -> String #

showList :: [Curry i j a x y] -> ShowS #

newtype Uncurry a z Source #

A type-level version of uncurry, it's used to convert between types of kind i -> j -> * and types of kind (i,j) -> *.

Constructors

UncurryLazy

The UncurryLazy constructor is useful when you need to construct/destruct an Uncurry a z value without placing restrictions on z

>>> :t (\(UncurryLazy axy) -> UncurryLazy axy) :: Uncurry a z -> Uncurry a z
(\(UncurryLazy axy) -> UncurryLazy axy) :: Uncurry a z -> Uncurry a z
  :: Uncurry a z -> Uncurry a z
>>> import Data.Tuple (swap)
>>> :t (\(UncurryLazy axy) -> UncurryLazy $ Flip $ swap axy) :: Uncurry (,) z -> Uncurry (Flip (,)) z
(\(UncurryLazy axy) -> UncurryLazy $ Flip $ swap axy) :: Uncurry (,) z -> Uncurry (Flip (,)) z
  :: Uncurry (,) z -> Uncurry (Flip (,)) z

It is slightly finnicky, and doesn't work well with function composition (i.e. .), and requires more hints from the compiler.

>>> :t (UncurryLazy . getUncurryLazy) :: Uncurry a z -> Uncurry a z

<interactive>:1:2: error:
    • Couldn't match type ‘a1 x0 y0’
                     with ‘forall x y. z1 ~ '(x, y) => a1 x y’
...
>>> :t (\(UncurryLazy axy) -> UncurryLazy axy)

<interactive>:1:36: error:
    • Couldn't match type ‘z’ with ‘'(x, y)’
        arising from a use of ‘axy’
        because type variables ‘x’, ‘y’ would escape their scope
...

Fields

Instances

Eq (a x y) => Eq (Uncurry k1 k a ((,) k k1 x y)) Source # 

Methods

(==) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

(/=) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

Ord (a x y) => Ord (Uncurry k1 k a ((,) k k1 x y)) Source # 

Methods

compare :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Ordering #

(<) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

(<=) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

(>) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

(>=) :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Bool #

max :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) #

min :: Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) -> Uncurry k1 k a ((k, k1) x y) #

Show (a x y) => Show (Uncurry k k1 a ((,) k1 k x y)) Source # 

Methods

showsPrec :: Int -> Uncurry k k1 a ((k1, k) x y) -> ShowS #

show :: Uncurry k k1 a ((k1, k) x y) -> String #

showList :: [Uncurry k k1 a ((k1, k) x y)] -> ShowS #

pattern UncurryStrict :: forall k k1 a x y. a x y -> Uncurry k k1 a ((,) k1 k x y) Source #

The UncurryStrict pattern is useful when you need to construct/destruct an 'Uncurry a '(x,y)' value

>>> :t UncurryStrict . getUncurryStrict
UncurryStrict . getUncurryStrict
  :: Uncurry a '(x, y) -> Uncurry a '(x, y)
>>> import Data.Tuple (swap)
>>> :t UncurryStrict . Flip . swap . getUncurryStrict
UncurryStrict . Flip . swap . getUncurryStrict
  :: Uncurry (,) '(x, y) -> Uncurry (Flip (,)) '(x, y)

It works well with function composition and requires fewer hints, but cannot be used to construct or match values of type Uncurry a z, such as are needed by fmap.

>>> :t (\(UncurryLazy axy) -> UncurryStrict axy) :: Uncurry a z -> Uncurry a z

<interactive>:1:38: error:
    • Couldn't match type ‘z1’ with ‘'(x0, y0)’
...
    • In the first argument of ‘UncurryStrict’, namely ‘axy’
...
>>> :t (\(UncurryStrict axy) -> UncurryLazy axy) :: Uncurry a z -> Uncurry a z

<interactive>:1:4: error:
    • Couldn't match type ‘z1’ with ‘'(x0, y0)’
...
    • In the pattern: UncurryStrict axy
...

However, it is very useful when paired with toProduct.

getUncurryStrict :: Uncurry a '(x, y) -> a x y Source #

a pseudo-record accessor, corresponding to matching the UncurryStrict pattern. Can be useful when paired with fromProduct

uncurried :: (forall x y. a x y -> b x y) -> Uncurry a z -> Uncurry b z Source #

a helper for lifting functions on curried types to functions on their uncurried equivalents. Very useful when using the Functor instance for Products.

>>> comma' = toProduct UncurryStrict . Pure . Compose . Pure $ ('a', True)
>>> :t comma'
comma' :: Product (Pure Char) (Pure Bool) (Uncurry (,))
>>> :t uncurried (const . snd) <$> comma'
uncurried (const . snd) <$> comma'
  :: Product (Pure Char) (Pure Bool) (Uncurry (->))

newtype Pure x a Source #

A type-level version of pure for Cont

Mainly useful when constructing continuation kind functors using Product and Coproduct.

Constructors

Pure 

Fields

Instances

Traversable i (Pure i x) Source # 

Methods

traverse :: Applicative j f => (forall a. a a -> f (b a)) -> t a -> f (Compose j (Pure i x -> *) t (Flip j (Pure i x) b)) Source #

sequenceA :: Applicative j f => t (Compose (Pure i x) (j -> *) f a) -> f (Compose j (Pure i x -> *) t (Flip j (Pure i x) a)) Source #

Foldable k (Pure k x) Source # 

Methods

foldr :: (forall a. a a -> b -> b) -> b -> t a -> b Source #

foldMap :: Monoid m => (forall a. a a -> m) -> t a -> m Source #

Applicative k (Pure k x) Source # 

Methods

pure :: (forall a. a a) -> f a Source #

(<*>) :: f ((Pure k x ~> a) b) -> f a -> f b Source #

Functor k (Pure k x) Source # 

Methods

fmap :: (forall a. a a -> b a) -> f a -> f b Source #

Eq (a x) => Eq (Pure k x a) Source # 

Methods

(==) :: Pure k x a -> Pure k x a -> Bool #

(/=) :: Pure k x a -> Pure k x a -> Bool #

Ord (a x) => Ord (Pure k x a) Source # 

Methods

compare :: Pure k x a -> Pure k x a -> Ordering #

(<) :: Pure k x a -> Pure k x a -> Bool #

(<=) :: Pure k x a -> Pure k x a -> Bool #

(>) :: Pure k x a -> Pure k x a -> Bool #

(>=) :: Pure k x a -> Pure k x a -> Bool #

max :: Pure k x a -> Pure k x a -> Pure k x a #

min :: Pure k x a -> Pure k x a -> Pure k x a #

Show (a x) => Show (Pure k x a) Source # 

Methods

showsPrec :: Int -> Pure k x a -> ShowS #

show :: Pure k x a -> String #

showList :: [Pure k x a] -> ShowS #