Maybe package:ghc-lib-parser

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.
The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

Examples

Basic usage:
>>> maybe False odd (Just 3)
True
>>> maybe False odd Nothing
False
Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
>>> import Text.Read ( readMaybe )

>>> maybe 0 (*2) (readMaybe "5")
10

>>> maybe 0 (*2) (readMaybe "")
0
Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
>>> maybe "" show (Just 5)
"5"

>>> maybe "" show Nothing
""
Maybe type indexed by open/closed
Why are two types MaybeApart? MARInfinite takes precedence: This is used (only) in Note [Infinitary substitution in lookup] in GHC.Core.InstEnv As of Feb 2022, we never differentiate between MARTypeFamily and MARTypeVsConstraint; it's really only MARInfinite that's interesting here.
The parameterizable maybe monad, obtained by composing an arbitrary monad with the Maybe monad. Computations are actions that may produce a value or exit. The return function yields a computation that produces that value, while >>= sequences two subcomputations, exiting if either computation does.
Like Maybe, but using unboxed sums. Use with care. Using a unboxed maybe is not always a win in execution *time* even when allocations go down. So make sure to benchmark for execution time as well. If the difference in *runtime* for the compiler is too small to measure it's likely better to use a regular Maybe instead. This is since it causes more function arguments to be passed, and potentially more variables to be captured by closures increasing closure size.
If a label is a local block label then return just its BlockId, otherwise Nothing.
Returns Just w if the operation is an integer comparison with width w, or Nothing otherwise.
Retrieves the template of an unfolding if possible maybeUnfoldingTemplate is used mainly when specialising, and we do want to specialise DFuns, so it's important to return a template for DFunUnfoldings