HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleboring-0.2.2Haskell2010

Data.Boring

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)

  • 4 classes
  • 3 values
  • Packageboring-0.2.2
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceBoring.hs

Classes

2 declarations
classclass 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.

Methods

Instances28Boring, …
classclass 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.

Methods

Instances15Absurd, …

Generic implementation

classclass GBoring (f :: Type -> Type) where
#

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.

Example3 expressions
data B2 = B2 () () deriving (Show, Generic)instance Boring B2boring :: B2B2 () ()
Instances4GBoring
classclass GAbsurd (f :: Type -> Type) where
#

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
Instances4GAbsurd

More interesting stuff

3 declarations
valuedevoid :: 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