Data.Boring

boring-0.2.2: Boring and Absurd types

Safe Haskell | Trustworthy
Language | Haskell2010

Data.Boring

Contents

- Classes
  - Generic implementation
- More interesting stuff

Description

`Boring` and `Absurd` classes. One approach.

Different approach would be to have

    -- none-one-tons semiring
    data NOT = None | One | Tons

    type family Cardinality (a :: *) :: NOT

    class Cardinality a ~ None => Absurd a where ...
    class Cardinality a ~ One  => Boring a where ...

This would make possible to define more instances, e.g.

    instance (Mult (Cardinality a) (Cardinality b) ~ None) => Absurd (a, b) where ...

### Functions

Function is an exponential:

    Cardinality (a -> b) ~ Exponent (Cardinality b) (Cardinality a)

or shortly `|a -> b| = |b| ^ |a|`. This gives us possible instances:

- `|a| = 0 => |a -> b| = m ^ 0 = 1`, i.e. ``Absurd` a => `Boring` (a -> b)`, or
- `|b| = 1 => |a -> b| = 1 ^ n = 1`, i.e. ``Boring` b => `Boring` (a -> b)`.

Both instances are `Boring`, but we chose to define the latter.

### Note about adding instances

At this moment this module misses a lot of instances, please make a patch to add more. Especially, if the package is already in the transitive dependency closure.

E.g. any possibly empty container `f` has ``Absurd` a => `Boring` (f a)`

Synopsis

- class Boring a where
  - boring :: a
- class Absurd a where
  - absurd :: a -> b
- class GBoring (f :: Type -> Type)
- class GAbsurd (f :: Type -> Type)
- vacuous :: (Functor f, Absurd a) => f a -> f b
- devoid :: Absurd s => p a (f b) -> s -> f s
- united :: (Boring a, Functor f) => (a -> f a) -> s -> f s

# Classes

class Boring a where #

`Boring` types which contains one thing, also `boring`. There is nothing interesting to be gained by comparing one element of the boring type with another, because there is nothing to learn about an element of the boring type by giving it any of your attention.

Boring Law:

    boring == x

Note: This is different class from `Default`. `Default` gives you some value, `Boring` gives you an unique value.

Also note, that we cannot have instances for e.g. `Either`, as both `(`Boring` a, `Absurd` b) => Either a b` and `(`Absurd` a, `Boring` b) => Either a b` would be valid instances.

Another useful trick, is that you can rewrite computations with `Boring` results, for example `foo :: Int -> ()`, if you are sure that `foo` is total.

    {-# RULES "less expensive" foo = boring #-}

That's particularly useful with equality `:~:` proofs.

Minimal complete definition

Nothing

Methods

boring :: a #

default boring :: (Generic a, GBoring (Rep a)) => a #

#### Instances

Instances details

Boring () # |
Instance details Defined in Data.Boring Methods boring :: () #
Boring a => Boring (Identity a) # |
Instance details Defined in Data.Boring Methods boring :: Identity a #
Boring p => Boring (Par1 p) # |
Instance details Defined in Data.Boring Methods boring :: Par1 p #
KnownChar n => Boring (SChar n) # |
Instance details Defined in Data.Boring Methods boring :: SChar n #
KnownSymbol n => Boring (SSymbol n) # |
Instance details Defined in Data.Boring Methods boring :: SSymbol n #
KnownNat n => Boring (SNat n) # |
Instance details Defined in Data.Boring Methods boring :: SNat n #
Absurd a => Boring (Maybe a) # | ``Maybe` a = a + 1`, `0 + 1 = 1`.
Instance details Defined in Data.Boring Methods boring :: Maybe a #
Absurd a => Boring [a] # | Recall regular expressions, kleene star of empty regexp is epsilon!
Instance details Defined in Data.Boring Methods boring :: [a] #
Boring (Proxy a) # |
Instance details Defined in Data.Boring Methods boring :: Proxy a #
Typeable a => Boring (TypeRep a) # |
Instance details Defined in Data.Boring Methods boring :: TypeRep a #
Boring (U1 p) # |
Instance details Defined in Data.Boring Methods boring :: U1 p #
(Boring a, Boring b) => Boring (a, b) # |
Instance details Defined in Data.Boring Methods boring :: (a, b) #
Boring b => Boring (a -> b) # |
Instance details Defined in Data.Boring Methods boring :: a -> b #
Boring a => Boring (Const a b) # |
Instance details Defined in Data.Boring Methods boring :: Const a b #
Coercible a b => Boring (Coercion a b) # | Coercibility is `Boring` too.
Instance details Defined in Data.Boring Methods boring :: Coercion a b #
a ~ b => Boring (a :~: b) # | Homogeneous type equality is `Boring` too.
Instance details Defined in Data.Boring Methods boring :: a :~: b #
Boring (f p) => Boring (Rec1 f p) # |
Instance details Defined in Data.Boring Methods boring :: Rec1 f p #
Boring b => Boring (Tagged a b) # |
Instance details Defined in Data.Boring Methods boring :: Tagged a b #
(Boring a, Boring b, Boring c) => Boring (a, b, c) # |
Instance details Defined in Data.Boring Methods boring :: (a, b, c) #
(Boring (f a), Boring (g a)) => Boring (Product f g a) # |
Instance details Defined in Data.Boring Methods boring :: Product f g a #
a ~~ b => Boring (a :~~: b) # | Heterogeneous type equality is `Boring` too.
Instance details Defined in Data.Boring Methods boring :: a :~~: b #
(Boring (f p), Boring (g p)) => Boring ((f :*: g) p) # |
Instance details Defined in Data.Boring Methods boring :: (f :*: g) p #
Boring c => Boring (K1 i c p) # |
Instance details Defined in Data.Boring Methods boring :: K1 i c p #
(Boring a, Boring b, Boring c, Boring d) => Boring (a, b, c, d) # |
Instance details Defined in Data.Boring Methods boring :: (a, b, c, d) #
Boring (f (g a)) => Boring (Compose f g a) # |
Instance details Defined in Data.Boring Methods boring :: Compose f g a #
Boring (f (g p)) => Boring ((f :.: g) p) # |
Instance details Defined in Data.Boring Methods boring :: (f :.: g) p #
Boring (f p) => Boring (M1 i c f p) # |
Instance details Defined in Data.Boring Methods boring :: M1 i c f p #
(Boring a, Boring b, Boring c, Boring d, Boring e) => Boring (a, b, c, d, e) # |
Instance details Defined in Data.Boring Methods boring :: (a, b, c, d, e) #

class Absurd a where #

The `Absurd` type is very exciting, because if somebody ever gives you a value belonging to it, you know that you are already dead and in Heaven and that anything you want is yours.

Similarly as there are many `Boring` sums, there are many `Absurd` products, so we don't have `Absurd` instances for tuples.

Minimal complete definition

Nothing

Methods

absurd :: a -> b #

default absurd :: (Generic a, GAbsurd (Rep a)) => a -> b #

#### Instances

Instances details

Absurd Void # |
Instance details Defined in Data.Boring Methods absurd :: Void -> b #
Absurd a => Absurd (NonEmpty a) # |
Instance details Defined in Data.Boring Methods absurd :: NonEmpty a -> b #
Absurd a => Absurd (Identity a) # |
Instance details Defined in Data.Boring Methods absurd :: Identity a -> b #
Absurd p => Absurd (Par1 p) # |
Instance details Defined in Data.Boring Methods absurd :: Par1 p -> b #
(Absurd a, Absurd b) => Absurd (Either a b) # |
Instance details Defined in Data.Boring Methods absurd :: Either a b -> b0 #
Absurd (V1 p) # |
Instance details Defined in Data.Boring Methods absurd :: V1 p -> b #
Absurd b => Absurd (Const b a) # |
Instance details Defined in Data.Boring Methods absurd :: Const b a -> b0 #
Absurd (f p) => Absurd (Rec1 f p) # |
Instance details Defined in Data.Boring Methods absurd :: Rec1 f p -> b #
Absurd a => Absurd (Tagged b a) # |
Instance details Defined in Data.Boring Methods absurd :: Tagged b a -> b0 #
(Absurd (f a), Absurd (g a)) => Absurd (Sum f g a) # |
Instance details Defined in Data.Boring Methods absurd :: Sum f g a -> b #
(Absurd (f p), Absurd (g p)) => Absurd ((f :+: g) p) # |
Instance details Defined in Data.Boring Methods absurd :: (f :+: g) p -> b #
Absurd c => Absurd (K1 i c p) # |
Instance details Defined in Data.Boring Methods absurd :: K1 i c p -> b #
Absurd (f (g a)) => Absurd (Compose f g a) # |
Instance details Defined in Data.Boring Methods absurd :: Compose f g a -> b #
Absurd (f (g p)) => Absurd ((f :.: g) p) # |
Instance details Defined in Data.Boring Methods absurd :: (f :.: g) p -> b #
Absurd (f p) => Absurd (M1 i c f p) # |
Instance details Defined in Data.Boring Methods absurd :: M1 i c f p -> b #

## Generic implementation

class GBoring (f :: Type -> Type) #

A helper class to implement `Generic` derivation of `Boring`.

Technically we could do (avoiding `QuantifiedConstraints`):

    type GBoring f = (Boring (f V.Void), Functor f)

    gboring :: forall f x. GBoring f => f x
    gboring = vacuous (boring :: f V.Void)

but separate class is cleaner.

    >>> data B2 = B2 () () deriving (Show, Generic)
    >>> instance Boring B2
    >>> boring :: B2
    B2 () ()

Minimal complete definition

gboring

#### Instances

Instances details

GBoring (U1 :: Type -> Type) # |
Instance details Defined in Data.Boring Methods gboring :: U1 a
(GBoring f, GBoring g) => GBoring (f :*: g) # |
Instance details Defined in Data.Boring Methods gboring :: (f :*: g) a
Boring c => GBoring (K1 i c :: Type -> Type) # |
Instance details Defined in Data.Boring Methods gboring :: K1 i c a
GBoring f => GBoring (M1 i c f) # |
Instance details Defined in Data.Boring Methods gboring :: M1 i c f a

class GAbsurd (f :: Type -> Type) #

A helper class to implement of `Generic` derivation of `Absurd`.

    type GAbsurd f = (Absurd (f ()), Functor f)

    gabsurd :: forall f x y. GAbsurd f => f x -> y
    gabsurd = absurd . void

Minimal complete definition

gabsurd

#### Instances

Instances details

GAbsurd (V1 :: Type -> Type) # |
Instance details Defined in Data.Boring Methods gabsurd :: V1 a -> b
(GAbsurd f, GAbsurd g) => GAbsurd (f :+: g) # |
Instance details Defined in Data.Boring Methods gabsurd :: (f :+: g) a -> b
Absurd c => GAbsurd (K1 i c :: Type -> Type) # |
Instance details Defined in Data.Boring Methods gabsurd :: K1 i c a -> b
GAbsurd f => GAbsurd (M1 i c f) # |
Instance details Defined in Data.Boring Methods gabsurd :: M1 i c f a -> b

# More interesting stuff

vacuous :: (Functor f, Absurd a) => f a -> f b #

If `Absurd` is uninhabited then any `Functor` that holds only values of type `Absurd` is holding no values.

devoid :: Absurd s => p a (f b) -> s -> f s #

There is a field for every type in the `Absurd`. Very zen.

    devoid :: Absurd s => Over p f s s a b

type Over p f s t a b = p a (f b) -> s -> f t

united :: (Boring a, Functor f) => (a -> f a) -> s -> f s #

We can always retrieve a `Boring` value from any type.

    united :: Boring a => Lens' s a