Module

Data.Operator.Top

Package
purescript-higher-order
Repository
matthew-hilty/purescript-higher-order

#Top1 Source

class Top1 (f :: Type -> Type)  where

The Top1 typeclass represents type constructors f that have a distinguished element top1 of type forall a. f a as well as an associated partial ordering (or at least a notion thereof), for which top1 is the minimum or lowest bound.

Because the notion of maximality entails the notion of comparability, the semantics of an instance of Top1 must be consistent with the definitional requirements of a partial order. In fact, many instances of Top1 are also instances of PartialOrd1 (and likely Ord1 as well).

In such cases, when a type operator f is both a registered instance of Top1 and one of PartialOrd1, it must satisfy the following law:

  • maximality: x .<=? top1 == Just true

Likewise, if f is an instance of Top1 and also an instance of Ord1, it must satisfy the following analogous law:

  • maximality: x .<= top1

Additionally, if f is an instance of a higher-order additive semigroup-like structure like Alt, f's top1 value must be one of the structure's annihilating elements:

  • Left annihilation: top1 + x .== top1
  • Right annihilation: x + top1 .== top1

Members

  • top1 :: forall a. f a

#Top1_ Source

class Top1_ (f :: Type -> Type)  where

The Top1_ typeclass represents type constructors f that have a distinguished function top1_ of type forall a. a -> f a as well as an associated partial ordering (or at least a notion thereof), for which the class of evaluations of top1_ constitutes the maximum or upper bound.

Because the notion of maximality entails the notion of comparability, the semantics of an instance of Top1_ must be consistent with the definitional requirements of a partial order. In fact, many instances of Top1_ are also instances of PartialOrd1 (and likely Ord1 as well).

In such cases, when a type operator f is both a registered instance of Top1_ and one of PartialOrd1, it must satisfy the following law:

  • maximality: x .<=? top1_ y == Just true

Likewise, if f is an instance of Top1_ and also an instance of Ord1, it must satisfy the following analogous law:

  • maximality: x .<= top1_ y

Additionally, if f is an instance of a higher-order additive semigroup-like structure like Alt, f's top1_ value must be one of the structure's annihilating elements:

  • Left annihilation: top1_ x + y .== top1_ x
  • Right annihilation: x + top1_ y .== top1_ y

Members

  • top1_ :: forall a. a -> f a

Instances

  • Top1_ Array

    Commonly, instances of Applicative admit a coarse interpratation as a higher-order bounded meet-semilattice with one or two equivalence classes such that pure serves as the top1_ upper bound. However, not all instances of Applicative can/should be interpreted this way; and other less-coarse interpretations may also be possible. Here's a counter-example:

    data Foo a = Low | Mid a | Hi a
    instance top1_Foo :: Top1_ Foo where
      top1_ = Hi
    instance ord1Foo :: Ord1 Foo where
      compare1 Low     Low     = EQ
      compare1 Low     _       = LT
      compare1 (Mid _) Low     = GT
      compare1 (Mid _) (Mid _) = EQ
      compare1 (Mid _) (Hi _)  = LT
      compare1 (Hi _)  (Hi _)  = EQ
      compare1 (Hi _)  _       = GT
    instance functorFoo :: Functor Foo where
      map f (Hi x) = Hi (f x)
      map f (Mid x) = Mid (f x)
      map _ Low = Low
    instance applyFoo :: Apply Foo where
      apply :: forall a b. f (a -> b) -> f a -> f b
      apply (Hi f) x = f <$> x
      apply (Mid f) x = f <$> x
      apply Low x = Low
    instance applicativeFoo :: Applicative Foo where
      pure = Mid
    
  • Top1_ CatList
  • Top1_ CatQueue
  • Top1_ First
  • Top1_ (Either a)
  • Top1_ (EitherR a)
  • Top1_ Last
  • Top1_ List
  • Top1_ Maybe
  • Top1_ Set
  • Top1_ ZipList
  • (Top1_ a) => Top1_ (ExceptT e a)
  • (Top k) => Top1_ (Map k)
  • Top1_ NonEmptySet
  • (Top1 f) => Top1_ f