Plutus.V1.Ledger.Interval

  • 1. 📜 Overview

  • 2. 🔧 LANGUAGE PRAGMAS AND IMPORTS

  • 3. 🗄️ Data Types

    • 3.1 ➰ Extended

    • 3.2 🆙 UpperBound

    • 3.3 🆕 LowerBound

    • 3.4 📏 Interval

  • 4. ⚙️ Functions

    • 4.1 ⚖️ strictUpperBound

    • 4.2 ⚖️ strictLowerBound

    • 4.3 🔽 lowerBound

    • 4.4 🔼 upperBound

    • 4.5 🏷️ interval

    • 4.6 🔢 singleton

    • 4.7 ▶️ from

    • 4.8 ◀️ to

    • 4.9 ♾️ always

    • 4.10 🚫 never

    • 4.11 🧮 member

    • 4.12 🔄 overlaps

    • 4.13 🛠️ intersection

    • 4.14 🏔️ hull

    • 4.15 🔍 contains

    • 4.16 📭 isEmpty

    • 4.17 ⏮️ before

    • 4.18 ⏭️ after

  • 5. 🤝 Typeclass Instances

  • 6. 🏭 On-Chain Derivations

  • 7. 📚 Glossary


1 📜 Overview

The Plutus.V1.Ledger.Interval module defines a generic interval type over any ordered domain, with support for open/closed and bounded/unbounded ends, plus a rich API for constructing and querying intervals:

  • Extended a: values extended with negative and positive infinity.

  • LowerBound a, UpperBound a: bound types carrying an Extended a and a closure flag.

  • Interval a: a pair of lower and upper bounds.

  • Functions: create intervals (interval, singleton, from, to, always, never) and query them (member, overlaps, etc.).

  • Instances: Functor, Eq, Ord, JoinSemiLattice, MeetSemiLattice, and Pretty for human-friendly rendering.

All key types derive Generic and NFData, and on-chain serialization is provided via makeIsDataIndexed and makeLift.


2 🔧 LANGUAGE PRAGMAS AND IMPORTS

  • DataKinds not needed here; key pragmas include generic deriving, template Haskell, and flexible/monomorphic binds.

  • NoImplicitPrelude: uses PlutusTx.Prelude for on-chain code.

  • OPTIONS_GHC ensure interface pragmas and specialization are preserved for on-chain performance.


3 🗄️ Data Types

3.1 ➰ Extended

  • Purpose: represent values with negative or positive infinity.

  • Example:

3.2 🆙 UpperBound

  • Fields:

    • Extended a endpoint.

    • Closure flag: True = inclusive (]), False = exclusive ()).

  • Example:

3.3 🆕 LowerBound

  • Closure: True = inclusive ([), False = exclusive (().

  • Example:

3.4 📏 Interval

  • Combines lower and upper bounds into an interval.

  • Example:


4 ⚙️ Functions

All functions are marked {-# INLINABLE #-} for on-chain compilation.

4.1 ⚖️ strictUpperBound

  • Inputs: endpoint a

  • Output: exclusive upper bound (a.

  • Example:

4.2 ⚖️ strictLowerBound

  • Exclusive lower bound (a.

4.3 🔽 lowerBound

  • Inclusive lower bound [a.

4.4 🔼 upperBound

  • Inclusive upper bound a].

4.5 🏷️ interval

  • Closed interval [lo,hi].

4.6 🔢 singleton

  • Single-value interval [x,x].

4.7 ▶️ from

  • Interval [lo, +∞].

4.8 ◀️ to

  • Interval [-∞, hi].

4.9 ♾️ always

  • Entire domain [-∞, +∞].

4.10 🚫 never

  • Empty interval.

4.11 🧮 member

  • Checks if x lies within interval i.

4.12 🔄 overlaps

  • True if intervals share any point.

4.13 🛠️ intersection

  • Largest common sub-interval.

4.14 🏔️ hull

  • Smallest interval containing both.

4.15 🔍 contains

  • Checks if one interval is inside another.

4.16 📭 isEmpty

  • True for empty intervals, including degenerate cases where bounds cross or close excludes endpoints.

4.17 ⏮️ before

  • True if x lies strictly before the interval’s start.

4.18 ⏭️ after

  • True if x is strictly after the interval’s end.


5 🤝 Typeclass Instances

  • Lifts functions over interval endpoints.

  • Join (/) = hull; bottom = empty interval.

  • Meet (/) = intersection; top = whole domain.

Explicit Eq and Ord instances via deriving strategies or INLINABLE definitions ensure correct on-chain behavior for Extended, UpperBound, LowerBound, and Interval.


6 🏭 On-Chain Derivations

  • Generates IsData and Lift for on-chain serialization and embedding.


7 📚 Glossary

  • Extended a: domain a extended with NegInf and PosInf.

  • Closure: Bool flag indicating inclusive (True) or exclusive (False) bound.

  • LowerBound/UpperBound: bound wrappers pairing an Extended a with a closure.

  • Interval a: value range from a lower to an upper bound.

  • Functor: structure supporting fmap for endpoints.

  • Join/Meet SemiLattice: algebraic classes for hull and intersection.

  • BoundedJoin/MeetSemiLattice: includes bottom (empty) and top (universal) elements.

  • INLINABLE: GHC pragma for on-chain specialization.

  • makeIsDataIndexed: TH for IsData instances with constructor indices.

  • makeLift: TH for embedding values in PlutusTx.

  • StrictData: pragma making all data fields strict.

  • NoImplicitPrelude: uses on-chain PlutusTx.Prelude in place of Haskell’s.

Last updated