plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Enum

Contents

Synopsis

Type classes

class POrd a => PCountable (a :: S -> Type) where Source #

A notion of 'next' value. More formally, instances of this type class are discrete linear orders with no maximal element.

Laws

  1. x /= psuccessor x
  2. y < x = psuccessor y <= x
  3. x < psuccessor y = x <= y

If you define psuccessorN, you must also ensure the following hold; the default implementation ensures this.

  1. psuccessorN 1 = psuccessor
  2. psuccessorN n . psuccessorN m = psuccessorN (n + m)

Law 1 ensures no value is its own successor. Laws 2 and 3 ensure that there are no 'gaps': every value is 'reachable' from any lower value by a finite number of applications of successor.

@since WIP

Minimal complete definition

psuccessor

Methods

psuccessor :: forall (s :: S). Term s (a :--> a) Source #

@since WIP

psuccessorN :: forall (s :: S). Term s (PPositive :--> (a :--> a)) Source #

The default implementation of this function is inefficient: if at all possible, give instances an optimized version that doesn't require recursion.

@since WIP

Instances

Instances details
PCountable PInteger Source #

@since WIP

Instance details

Defined in Plutarch.Enum

Methods

psuccessor :: forall (s :: S). Term s (PInteger :--> PInteger) Source #

psuccessorN :: forall (s :: S). Term s (PPositive :--> (PInteger :--> PInteger)) Source #

PCountable PPositive Source #

@since WIP

Instance details

Defined in Plutarch.Enum

Methods

psuccessor :: forall (s :: S). Term s (PPositive :--> PPositive) Source #

psuccessorN :: forall (s :: S). Term s (PPositive :--> (PPositive :--> PPositive)) Source #

class PCountable a => PEnumerable (a :: S -> Type) where Source #

Similar to PCountable, but has the ability to get a 'previous' value as well. More formally, instances of this type class are discrete linear orders with no maximal or minimal element.

Laws

  1. ppredecessor . psuccessor = psuccessor . ppredecessor = id

If you define ppredecessorN, you must also ensure the following hold; the default implementation ensures this.

  1. ppredecessorN 1 = ppredecessor
  2. ppredecessorN n . ppredecessorN m = ppredecessorN (n + m)

From Law 1, we obtain the following theorem:

  • x /= predecessor x

@since WIP

Minimal complete definition

ppredecessor

Methods

ppredecessor :: forall (s :: S). Term s (a :--> a) Source #

@since WIP

ppredecessorN :: forall (s :: S). Term s (PPositive :--> (a :--> a)) Source #

The default implementation of this function is inefficient: if at all possible, give instances an optimized version that doesn't require recursion.

@since WIP

Instances

Instances details
PEnumerable PInteger Source #

@since WIP

Instance details

Defined in Plutarch.Enum

Methods

ppredecessor :: forall (s :: S). Term s (PInteger :--> PInteger) Source #

ppredecessorN :: forall (s :: S). Term s (PPositive :--> (PInteger :--> PInteger)) Source #