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

ModuleAgda-2.7.0.1Haskell2010

Agda.Utils.Either

Utilities for the Either type.

  • 18 values
  • PackageAgda-2.7.0.1
  • Exports18
  • LanguageHaskell2010
  • LicenceMIT
  • SourceEither.hs
valuewhileLeft
  1. :: Monad m
  2. => a -> Either b c
  3. -> a -> b -> m a
  4. -> a -> c -> m d
  5. -> a
  6. -> m d
#

Loop while we have an exception.

valuecaseEitherM :: Monad m => m (Either a b) -> (a -> m c) -> (b -> m c) -> m c
#

Monadic version of either with a different argument ordering.

valueisLeft :: Either a b -> Bool
#

Return True if the given value is a Left-value, False otherwise.

Examples

Basic usage:

Example2 expressions
isLeft (Left "foo")TrueisLeft (Right 3)False

Assuming a Left value signifies some sort of error, we can use isLeft to write a very simple error-reporting function that does absolutely nothing in the case of success, and outputs "ERROR" if any error occurred.

This example shows how isLeft might be used to avoid pattern matching when one does not care about the value contained in the constructor:

Example4 expressions
import Control.Monad ( when )let report e = when (isLeft e) $ putStrLn "ERROR"report (Right 1)report (Left "parse error")ERROR
valueisRight :: Either a b -> Bool
#

Return True if the given value is a Right-value, False otherwise.

Examples

Basic usage:

Example2 expressions
isRight (Left "foo")FalseisRight (Right 3)True

Assuming a Left value signifies some sort of error, we can use isRight to write a very simple reporting function that only outputs "SUCCESS" when a computation has succeeded.

This example shows how isRight might be used to avoid pattern matching when one does not care about the value contained in the constructor:

Example4 expressions
import Control.Monad ( when )let report e = when (isRight e) $ putStrLn "SUCCESS"report (Left "parse error")report (Right 1)SUCCESS
valuemaybeLeft :: Either a b -> Maybe a
#

Safe projection from Left.

maybeLeft (Left a) = Just a
maybeLeft Right{}  = Nothing
valueallRight :: [Either a b] -> Maybe [b]
#

Returns Just input_with_tags_stripped if all elements are to the right, and otherwise Nothing.

 allRight xs ==
   if all isRight xs then
     Just (map ((Right x) -> x) xs)
    else
     Nothing