graphted-0.3.1.0: Graph indexed monads.

Copyright(c) Aaron Friel
LicenseBSD-3
MaintainerAaron Friel <mayreply@aaronfriel.com>
Stabilityunstable
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.MonadFail.Graph

Description

This is only used in Do Notation with refutable patterns. e.g.:

    do  Just a <- m
        k a

Is desugared as:

    let f (Just a) = k a
        f _        = fail "Pattern match failure in do expression..."    
    in m >>= k

With -XApplicativeDo, there are two outstanding issues:

First, This will not compile (https:/ghc.haskell.orgtracghcticket/13648) as the body statements m1 and m2 are desugared incorrectly:

    f m1 m2 k = do
        m1
        m2
        k

To resolve, replace m1 with _ <- m1.

Second, fail must be in scope (https:/ghc.haskell.orgtracghcticket/13649) when wildcard patterns are used. The module Prelude.Graphted takes care of this, and custom preludes must as well. A GMonadFail constraint will not be added unless a refutable pattern is used.

Synopsis

Documentation

class GMonad m => GMonadFail m where Source #

Graph indexed monad with failure.

Associated Types

type Fail m :: p Source #

The unit failure element of the index.

Default instance: Fail m = Unit m

Methods

gfail :: String -> m (Fail m) a Source #

Fail with a message.

Default implementation requires the default instance of Fail.

gfail :: (GMonadZero m, Zero m ~ Fail m) => String -> m (Fail m) a Source #

Fail with a message.

Default implementation requires the default instance of Fail.

Instances

Monad m => GMonadFail * (GWrapped m) Source # 

Associated Types

type Fail (GWrapped m) (m :: GWrapped m -> * -> *) :: p Source #

Methods

gfail :: String -> m (Fail (GWrapped m) m) a Source #

IxMonadZero * m => GMonadFail (*, *) (WrappedIx m) Source # 

Associated Types

type Fail (WrappedIx m) (m :: WrappedIx m -> * -> *) :: p Source #

Methods

gfail :: String -> m (Fail (WrappedIx m) m) a Source #