each-0.1.0.0: Template Haskell library for writing monadic expressions more easily

Copyright(c) dramforever 2017
LicenseBSD3
Maintainerdramforever
Stabilityexperimental
Portabilitynon-portable (Template Haskell)
Safe HaskellNone
LanguageHaskell2010

Each

Description

The basic structure of an each block is this:

$(each [| ... |])

Inside of this block, three (interchangable) ways are used to mark impure subexpressions:

  • bind expr
  • bind $ expr
  • (~! expr)

When each encounters such a subexpression, appropriate calls to fmap, <*> and join are generated so that the results generally match what you would expect. In particular, The impure actions are evaluated from left to right, so that:

$(each [| bind getLine ++ bind getLine ])

means

(++) `fmap` getLine <*> getLine

Type signatures

Type signatures like (x :: t), when used on expressions containing bind, i.e. impure subexpressions, are transformed in one of the following ways:

  • With PartialTypeSignatures, the generated context type will be a wildcard, requiring GHC to infer the context. In this case (z :: t) where contains an impure subexpression, is transfomed into (z' :: _ t), where z' is the transformed form of z.
  • With eachWith, the context type is as supplied. For examples see eachWith.

Synopsis

Documentation

each :: ExpQ -> ExpQ Source #

Invoke an each block. Intended to be used as

$(each [| ... |])

eachWith :: TypeQ -> ExpQ -> ExpQ Source #

Invoke an each block while specifying the context type, so that type annotations may be processed appropriately.

$(eachWith [t| IO |] [| "Hello, " ++ (bind getLine :: String) |])

means

("Hello, " ++) `fmap` (getLine :: IO String)

using the IO type which is supplied to eachWith.

bind :: () Source #

Do not use this outside of an each block. Only its name is used, and its value itself does not make sense.

(~!) :: () Source #

Do not use this outside of an each block. Only its name is used, and its value itself does not make sense.