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

Moduleouroboros-consensus-4.2.1.0

Ouroboros.Consensus.HardFork.Combinator.Degenerate

  • 8 types
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"
Instances170Bifoldable, Bifoldable1, Bifunctor, Bitraversable, Eq2, Ord2, …
data familydata family BlockConfig blk
#
Instances7Isomorphic, NoThunks, BlockConfig, …
data familydata family CodecConfig blk
#
Instances7Isomorphic, Generic, NoThunks, Rep, CodecConfig, …
data familydata family Header blk
#
Instances33GetHeader1, Inject, Isomorphic, StandardHash, ShowProxy, HasNestedContent, …
datadata TopLevelConfig blk
#
Instances4Isomorphic, Generic, NoThunks, Rep
newtypenewtype HardForkBlock (xs :: [Type])
#
Instances150SameDepIndex2, StandardHash, HasNestedContent, ReconstructNestedCtxt, ApplyBlock, CanUpgradeLedgerTables, …
datadata HardForkLedgerConfig (xs :: [Type])
#
Instances5Show, Generic, NoThunks, SerialiseNodeToClient, Rep
datadata HardForkEnvelopeErr (xs :: [Type])
#
Instances5Eq, Show, Generic, NoThunks, Rep
datadata HardForkLedgerError (xs :: [Type])
#
Instances5Eq, Show, Generic, NoThunks, Rep
datadata HardForkApplyTxErr (xs :: [Type])
#
Instances6ShowProxy, Eq, Show, Generic, SerialiseNodeToClient, Rep
data familydata family LedgerState blk (mk :: MapKind)
#
Instances39ApplyBlock, CanUpgradeLedgerTables, IsLedger, SerializeTablesWithHint, IndexedMemPack, CanStowLedgerTables, …
data familydata family BlockQuery :: Type -> QueryFootprint -> Type -> Type
#
Instances14SameDepIndex2, SerialiseBlockQueryResult, SerialiseNodeToClient, ShowQuery, ShowProxy, Show, …
data familydata family GenTx blk
#
Instances48Inject, Isomorphic, ShowProxy, Eq, Ord, Show, …
data familydata family TxId blk
#
Instances21ShowProxy, Eq, Ord, Show, Generic, NoThunks, …
data familydata family ConsensusConfig p
#
Instances16Generic, NoThunks, Rep, ConsensusConfig, …