overloaded-0.2.1: Overloaded pragmas as a plugin

Safe HaskellSafe
LanguageHaskell2010

Overloaded.Do

Contents

Description

Overloaded "local" do-blocks.

Inspired by Local Do GHC-proposal. Yet because we do desugaring in reader phase, we must have a bit more complicated setup.

The expressions like

ex2d :: IxStateT Identity Int String ()
ex2d = ixmonad.do
    _unused <- ixmodify show
    ixmodify reverse

are desugared into

ex2b :: IxStateT Identity Int String ()
ex2b =
    ixmonad @Bind (ixmodify show) $ \_unused ->
    ixmodify reverse

Allowing to locally overload what do desugars to.

The monad in this module is an example how to define a desugaring. We need to it this way, so the names are easily accessible in renamer phase. (I.e. constant, then transformation is pure, as we don't need to lookup them for each do-block).

Enabled with:

{-# OPTIONS -fplugin=Overloaded -fplugin-opt=Overloaded:Do #-}
Synopsis

Do desugaring methods

Type aliases

type Pure = Pure Source #

type Then = Then Source #

type Bind = Bind Source #

Default Monad desugaring

class Monad' (method :: DoMethod) (ty :: Type) where Source #

Methods

monad :: ty Source #

Instances
(ty ~ (a -> m a), Applicative m) => Monad' Pure ty Source # 
Instance details

Defined in Overloaded.Do

Methods

monad :: ty Source #

(ty ~ (m a -> m b -> m b), Applicative m) => Monad' Then ty Source # 
Instance details

Defined in Overloaded.Do

Methods

monad :: ty Source #

(ty ~ (m a -> (a -> m b) -> m b), Monad m) => Monad' Bind ty Source # 
Instance details

Defined in Overloaded.Do

Methods

monad :: ty Source #