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

Moduleutility-ht-0.0.17.2Haskell98

Data.Maybe.HT

  • 3 values
Example1 expression
import Control.Monad (guard)
valuetoMaybe :: Bool -> a -> Maybe a
#

Returns Just if the precondition is fulfilled. prop> b x -> (guard b >> x) == (toMaybe b =<< (x::Maybe Char))

value(?->) :: Maybe a -> (a -> b) -> Maybe b
#

This is an infix version of fmap for writing select style expressions using test functions, that produce Maybes.

The precedence is chosen to be higher than (:), in order to allow:

alternatives default $
   checkForA ?-> (\a -> f a) :
   checkForB ?-> (\b -> g b) :
   []

The operation is left associative in order to allow to write

checkForA ?-> f ?-> g

which is equivalent to

checkForA ?-> g . f

due to the functor law.