About

Metadata

  • Last updated , by 414owen
  • License MIT
  • Maintained by: owen@owen.cafe

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 9.6.2
  2. 9.4.5
  3. 9.2.8
  4. 9.0.2
  5. 8.10.7
  6. 8.8.4
  7. 8.6.5
  8. 8.4.4
  9. 8.2.2
  10. 8.0.2
  11. 7.10.3

Readme

multi-except

Hackage version CI Status GitHub License

multi-except - succeed, or return one or more errors

Adding the dependency

-- in your cabal file
  -- Add the main package (only depends on base!)
  , multi-except
  -- For the Alt instance (depends on semigroupoids)
  , multi-except:semigroupoid-instances

Usage

{-# LANGUAGE ApplicativeDo #-}

import Control.Applicative.MultiExcept

errors :: MultiExcept String (Int, Int, Int)
errors = do
  a <- throwError "no monad instance"
  b <- pure 12
  c <- throwError "i am scared"
  pure (a, b, c)

-- errors: Errors ["no monad instance", "i am scared"]

The use of ApplicativeDo is significant and necessary for using MultiExcept with do notation.

MultiExcept is not a Monad, only an Applicative, so a few constraints apply, such as not being able to determine the structure of the rest of the computation based on a previously do-bound value. If the previous sentence was confusing, then you might want to consider using a writer monad instead.

To compose with other applicative effects, you can use Data.Functor.Compose.