Applicative do

Contents
  • The desugaring
  • Preservation of Monad semantics
  • Applicatives without Monads
    • validation
    • async
    • optparse-applicative
  • When Applicative is more efficient
    • haxl
    • containers
  • With only a Functor

Normally, do notation is syntactic sugar over monadic functions and desugars into monadic combinators such as (>>=). The ApplicativeDo language extension enables an alternate desugaring, allowing do syntax to be used in an Applicative context as well.

There are two reasons to enable the ApplicativeDo extension:

  1. When a type constructor has an Applicative but no Monad.
  2. When composition using (<*>) is more efficient than the corresponding composition using (>>=).

There is (in principle) no reason not to enable ApplicativeDo, but see the preservation of monad semantics section below for caveats.

ApplicativeDo was introduced into GHC Release notes for GHC 8.0.1 in version 8.0.1 in 2016.

Sign up for access to the full page, plus the complete archive and all the latest content.