HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelinear-base-0.4.0Haskell2010

Data.Maybe.Linear

This module provides linear functions on the standard Maybe type.

  • 1 type
  • 5 values
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

Instances63Monad, MonadFix, MonadFail, Applicative, Foldable, Alternative, …
valuemaybe :: b -> (a %1 -> b) -> Maybe a %1 -> b
#

maybe b f m returns (f a) where a is in m if it exists and b otherwise

valuefromMaybe :: a -> Maybe a %1 -> a
#

fromMaybe default m is the a in m if it exists and the default otherwise

valuemaybeToList :: Maybe a %1 -> [a]
#

maybeToList m creates a singleton or an empty list based on the Maybe a.

valuecatMaybes :: [Maybe a] %1 -> [a]
#

catMaybes xs discards the Nothings in xs and extracts the as

valuemapMaybe :: (a %1 -> Maybe b) -> [a] %1 -> [b]
#
mapMaybe f xs = catMaybes (map f xs)