-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a builder for unrestricted monads
- Loading branch information
Showing
3 changed files
with
45 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
|
||
module Control.Monad.Builder | ||
( BuilderType(..) | ||
, monadBuilder | ||
) where | ||
|
||
-- TODO: Link to example of builder | ||
|
||
import qualified Control.Monad as Unrestricted hiding (fail) | ||
import qualified Control.Monad.Fail as Unrestricted | ||
import Prelude.Linear (String) | ||
|
||
-- | Type of 'monadBuilder'. Note how the constraint on @m@ varies depending on | ||
-- the field. The constraints are solved lazily when a field is used by the do | ||
-- notation (in particular, if you don't do a pattern-matching, then you don't | ||
-- need a 'LMonadFail'). | ||
data BuilderType = Builder | ||
{ (>>=) :: forall m a b. Unrestricted.Monad m => m a -> (a -> m b) -> m b | ||
, (>>) :: forall m b. Unrestricted.Monad m => m () -> m b -> m b | ||
, fail :: forall m a. Unrestricted.MonadFail m => String -> m a | ||
, return :: forall m a. Unrestricted.Monad m => a -> m a | ||
-- See also 'Control.Monad.Linear.Builder.return' | ||
} | ||
|
||
-- | A builder to be used with @-XRebindableSyntax@ in conjunction with | ||
-- @RecordWildCards@ | ||
monadBuilder :: BuilderType | ||
monadBuilder = Builder | ||
{ (>>=) = (Unrestricted.>>=) | ||
, (>>) = (Unrestricted.>>) | ||
, fail = Unrestricted.fail | ||
, return = Unrestricted.return } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters