Safe Haskell | None |
---|---|

Language | Haskell2010 |

- class FunctorB b => ProductB b where
- bzip :: ProductB b => b f -> b g -> b (Product f g)
- bunzip :: ProductB b => b (Product f g) -> (b f, b g)
- bzipWith :: ProductB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h
- bzipWith3 :: ProductB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i
- bzipWith4 :: ProductB b => (forall a. f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j
- (/*/) :: ProductB b => b f -> b g -> b (Prod '[f, g])
- (/*) :: ProductB b => b f -> b (Prod fs) -> b (Prod (f ': fs))
- type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target G)), Generic (b (Target FxG)), GProductB (Rep (b (Target F))), Rep (b (Target G)) ~ Repl (Target F) (Target G) (Rep (b (Target F))), Rep (b (Target FxG)) ~ Repl (Target F) (Target FxG) (Rep (b (Target F))))
- type CanDeriveGenericInstance' b = (Generic (b (Target F)), GProductB (Rep (b (Target F))))
- class GProductB b
- gbprodDefault :: CanDeriveGenericInstance b => b f -> b g -> b (Product f g)
- gbuniqDefault :: CanDeriveGenericInstance' b => (forall a. f a) -> b f

# Documentation

class FunctorB b => ProductB b where Source #

Barbie-types that can form products, subject to the laws:

`bmap`

(`Pair`

a _) .`uncurry`

.`bprod`

=`fst`

`bmap`

(`Pair`

_ b) .`uncurry`

.`bprod`

=`snd`

Notice that because of the laws, having an internal product structure is not enough to have a lawful instance. E.g.

data Ok f = Ok {o1 :: f`String`

, o2 :: f`Int`

} -- has an instance data Bad f = Bad{b1 :: f`String`

, hiddenFromArg:`Int`

} -- no lawful instance

Intuitively, the laws for this class require that `b`

hides no structure
from its argument `f`

. Because of this, any `x :: forall a . f a`

determines a unique value of `b f`

, witnessed by the `buniq`

method.
Formally:

`const`

(`buniq`

x) =`bmap`

(`const`

x)

There is a default implementation of `bprod`

and `buniq`

for `Generic`

types,
so instances can derived automatically.

bunzip :: ProductB b => b (Product f g) -> (b f, b g) Source #

An equivalent of `unzip`

for Barbie-types.

bzipWith :: ProductB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h Source #

An equivalent of `zipWith`

for Barbie-types.

bzipWith3 :: ProductB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i Source #

An equivalent of `zipWith3`

for Barbie-types.

bzipWith4 :: ProductB b => (forall a. f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j Source #

An equivalent of `zipWith4`

for Barbie-types.

(/*) :: ProductB b => b f -> b (Prod fs) -> b (Prod (f ': fs)) infixr 4 Source #

Similar to `/*/`

but one of the sides is already a 'Prod fs'.

Note that `/*`

, `/*/`

and `uncurryn`

are meant to be used together:
`/*`

and `/*/`

combine `b f1, b f2...b fn`

into a single product that
can then be consumed by using `uncurryn`

on an n-ary function. E.g.

f :: f a -> g a -> h a -> i a`bmap`

(`uncurryn`

f) (bf`/*`

bg`/*/`

bh)

type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target G)), Generic (b (Target FxG)), GProductB (Rep (b (Target F))), Rep (b (Target G)) ~ Repl (Target F) (Target G) (Rep (b (Target F))), Rep (b (Target FxG)) ~ Repl (Target F) (Target FxG) (Rep (b (Target F)))) Source #

type CanDeriveGenericInstance' b = (Generic (b (Target F)), GProductB (Rep (b (Target F)))) Source #

gbprod, gbuniq

gbprodDefault :: CanDeriveGenericInstance b => b f -> b g -> b (Product f g) Source #

gbuniqDefault :: CanDeriveGenericInstance' b => (forall a. f a) -> b f Source #