HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Moduleplutus-tx-1.70.0.0

PlutusTx.Prelude

  • 26 types
  • 21 classes
  • 116 values
value(=<<) :: Monad m => (a -> m b) -> m a -> m b
#

Same as >>=, but with the arguments interchanged.

as >>= f == f =<< as
valueotherwise :: Bool
#

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
     | otherwise = ...
value($) :: (a -> b) -> a -> b
#
value(.) :: (b -> c) -> (a -> b) -> a -> c
#
valueconst :: a -> b -> a
#
valuecurry :: ((a, b) -> c) -> a -> b -> c
#
valueflip :: (a -> b -> c) -> b -> a -> c
#
valuefst :: (a, b) -> a
#
valueid :: a -> a
#
valuesnd :: (a, b) -> b
#
valueuncurry :: (a -> b -> c) -> (a, b) -> c
#
valueuntil :: (a -> Bool) -> (a -> a) -> a -> a
#
valuefix :: ((a -> b) -> a -> b) -> a -> b
#
value(<$>) :: Functor f => (a -> b) -> f a -> f b
#
value(<&>) :: Functor f => f a -> (a -> b) -> f b
#
method(>>) :: m a -> m b -> m b
#

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.

'as >> bs' can be understood as the do expression

do as
   bs

or in terms of (>>=) as

as >>= const bs
method(>>=) :: m a -> (a -> m b) -> m b
#

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

'as >>= bs' can be understood as the do expression

do a <- as
   bs a

An alternative name for this function is 'bind', but some people may refer to it as 'flatMap', which results from it being equivalent to

\x f -> join (fmap f x) :: Monad m => m a -> (a -> m b) -> m b

which can be seen as mapping a value with Monad m => m a -> m (m b) and then 'flattening' m (m b) to m b using join.

methodreturn :: a -> m a
#

Inject a value into the monadic type. This function should not be different from its default implementation as pure. The justification for the existence of this function is merely historic.

datadata Either a b
#

The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

Examples

The type Either String Int is the type of values which can be either a String or an Int. The Left constructor can be used only on Strings, and the Right constructor can be used only on Ints:

Example6 expressions
let s = Left "foo" :: Either String IntsLeft "foo"let n = Right 3 :: Either String IntnRight 3:type ss :: Either String Int:type nn :: Either String Int

The fmap from our Functor instance will ignore Left values, but will apply the supplied function to values contained in a Right:

Example4 expressions
let s = Left "foo" :: Either String Intlet n = Right 3 :: Either String Intfmap (*2) sLeft "foo"fmap (*2) nRight 6

The Monad instance for Either allows us to chain together multiple actions which may fail, and fail overall if any of the individual steps failed. First we'll write a function that can either parse an Int from a Char, or fail.

Example3 expressions
import Data.Char ( digitToInt, isDigit ):{    let parseEither :: Char -> Either String Int        parseEither c          | isDigit c = Right (digitToInt c)          | otherwise = Left "parse error":}

The following should work, since both '1' and '2' can be parsed as Ints.

Example2 expressions
:{    let parseMultiple :: Either String Int        parseMultiple = do          x <- parseEither '1'          y <- parseEither '2'          return (x + y):}
Example1 expression
parseMultipleRight 3

But the following should fail overall, since the first operation where we attempt to parse 'm' as an Int will fail:

Example2 expressions
:{    let parseMultiple :: Either String Int        parseMultiple = do          x <- parseEither 'm'          y <- parseEither '2'          return (x + y):}
Example1 expression
parseMultipleLeft "parse error"

Constructors

Instances161Bifoldable, Bifoldable1, Bifunctor, Bitraversable, Eq2, Ord2, …
datadata Ordering
#
Instances40Bounded, Data, Read, Show, Ix, Generic, …
classclass Functor f => Applicative (f :: Type -> Type) where
#

Methods

  • pure :: a -> f a
  • (<*>) :: f (a -> b) -> f a -> f binfixl 4
Instances5Applicative
newtypenewtype BuiltinByteStringUtf8
#
Instances12Eq, Ord, Show, IsString, Semigroup, Monoid, …
Instances15Show, NFData, Pretty, FromData, ToData, UnsafeFromData, …
Instances15Show, NFData, Pretty, FromData, ToData, UnsafeFromData, …
Instances13Eq, Show, NFData, Pretty, FromData, ToData, …
datadata BuiltinByteString
#
Instances31Data, IsString, NFData, Pretty, Hashable, Serialise, …
datadata BuiltinData
#
Instances24Data, Ord, Generic, NFData, Pretty, FromData, …
datadata BuiltinList a
#
Instances14Lift, Eq, Data, Ord, Show, HasBlueprintDefinition, …
datadata BuiltinPair a b
#
Instances14Lift, Eq, Data, Ord, Show, HasBlueprintDefinition, …
datadata BuiltinString
#
Instances18Data, Ord, IsString, Monoid, HasBlueprintDefinition, Semigroup, …
datadata BuiltinUnit
#
Instances10Data, HasBlueprintDefinition, HasFromBuiltin, Lift, HasBlueprintSchema, HasFromOpaque, …
classclass Enum a where
#

Methods

Instances5Enum
  • Enum IntegerDefined in plutus-tx-1.70.0.0 · PlutusTx.Enum.Class
  • Enum BoolDefined in plutus-tx-1.70.0.0 · PlutusTx.Enum · orphan
  • Enum OrderingDefined in plutus-tx-1.70.0.0 · PlutusTx.Enum · orphan
  • Enum RationalDefined in plutus-tx-1.70.0.0 · PlutusTx.Ratio
  • Enum ()Defined in plutus-tx-1.70.0.0 · PlutusTx.Enum · orphan
classclass Eq a where
#

Methods

Instances41Eq, …
  • Eq IntegerDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq BoolDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • Eq OrderingDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • Eq BuiltinBLS12_381_G1_ElementDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq BuiltinBLS12_381_G2_ElementDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq BuiltinByteStringDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq BuiltinDataDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq BuiltinStringDefined in plutus-tx-1.70.0.0 · PlutusTx.Eq.Class
  • Eq RationalDefined in plutus-tx-1.70.0.0 · PlutusTx.Ratio
  • Eq ()Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • Eq (List a)Defined in plutus-tx-1.70.0.0 · PlutusTx.Data.List
  • Eq a => Eq (Maybe a)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • Eq a => Eq [a]Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b) => Eq (Either a b)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b) => Eq (These a b)Defined in plutus-tx-1.70.0.0 · PlutusTx.These
  • (Eq a, Eq b) => Eq (a, b)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c) => Eq (a, b, c)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v, Eq w) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v, Eq w, Eq x) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v, Eq w, Eq x, Eq y) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v, Eq w, Eq x, Eq y, Eq z) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
  • (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p, Eq q, Eq r, Eq s, Eq t, Eq u, Eq v, Eq w, Eq x, Eq y, Eq z, Eq t26) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, t26)Defined in plutus-tx-1.70.0.0 · PlutusTx.Eq · orphan
classclass Functor (f :: Type -> Type) where
#

Methods

  • fmap :: (a -> b) -> f a -> f b
Instances9Functor, …
  • Functor IdentityDefined in plutus-tx-1.70.0.0 · PlutusTx.Functor
  • Functor MaybeDefined in plutus-tx-1.70.0.0 · PlutusTx.Functor
  • Functor MaxDefined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
  • Functor MinDefined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
  • Functor []Defined in plutus-tx-1.70.0.0 · PlutusTx.Functor
  • Functor (Either c)Defined in plutus-tx-1.70.0.0 · PlutusTx.Functor
  • Functor (Tuple2 c)Defined in plutus-tx-1.70.0.0 · PlutusTx.Functor
  • Functor (Map k)Defined in plutus-tx-1.70.0.0 · PlutusTx.AssocMap
  • Functor (Const m)Defined in plutus-tx-1.70.0.0 · PlutusTx.Functor
classclass FromData a where
#
Instances22FromData, …
classclass ToData a where
#

Methods

Instances22ToData, …
classclass UnsafeFromData a where
#
Instances22UnsafeFromData, …
classclass Semigroup a => Monoid a where
#

Methods

Instances16Monoid, …
classclass Eq a => Ord a where
#

Methods

Instances36Ord, …
datadata Rational
#
Instances25Show, Generic, Pretty, FromJSON, ToJSON, FromData, …
newtypenewtype Max a
#

Constructors

Instances2Functor, Semigroup
  • Functor MaxDefined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
  • Ord a => Semigroup (Max a)Defined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
newtypenewtype Min a
#

Constructors

Instances2Functor, Semigroup
  • Functor MinDefined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
  • Ord a => Semigroup (Min a)Defined in plutus-tx-1.70.0.0 · PlutusTx.Semigroup
classclass Semigroup a where
#

Methods

  • (<>) :: a -> a -> ainfixr 6
Instances18Semigroup, …
datadata Integer
#

Arbitrary precision integers. In contrast with fixed-size integral types such as Int, the Integer type represents the entire infinite range of integers.

Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.

If the value is small (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively.

Invariant: IP and IN are used iff the value does not fit in IS.

Instances111Data, Num, Read, Real, Ix, Bits, …
datadata Maybe a
#

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.

The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.

Constructors

Instances163Monad, MonadFix, MonadFail, Alternative, MonadPlus, MonadZip, …
datadata Bool
#
Instances108Bounded, Data, Read, Ix, Generic, Bits, …