ListT is:exact
A generator with side-effects.
The list monad transformer, which extends a monad with non-determinism
The type variables signify:
- m - The base monad
- a - The values that the computation yields
throughout its execution
For basic construction and composition of
ListT computations,
much can be accomplished using common typeclass methods.
- return corresponds to yield, yielding a single
value.
- (>>=) corresponds to for, calling the second
computation once for each time the first computation
yields.
- mempty neither yields any values nor produces any
effects in the base monad.
- (<>) sequences two computations, yielding all
the values of the first followed by all the values of the second.
- lift converts an action in the base monad into a ListT
computation which performs the action and yields a single
value.
ListT is a newtype wrapper for
Producer. You will likely
need to use
Select and
enumerate to convert back and
forth between these two types to take advantage of all the
Producer-related utilities that
Pipes.Prelude has to
offer.
A proper implementation of the list monad-transformer. Useful for
streaming of monadic data structures.
Since it has instances of
MonadPlus and
Alternative, you
can use general utilities packages like
"monadplus" with it.
Lazy monadic computation of a list of results.
A list monad transformer / a monadic list.
Monadic list example: A program which reads numbers from the user and
accumulates them.
import Control.Monad.ListT.Funcs (repeatM)
import Data.List.Class (execute, scanl, takeWhile, mapL)
import Prelude hiding (scanl, takeWhile)
main =
execute . mapL print .
scanl (+) 0 .
fmap (fst . head) .
takeWhile (not . null) .
fmap reads $ repeatM getLine
Note: The
transformers package also has a
ListT type,
which oddly enough it is not a list monad transformer. This module was
deliberately named differently from
transformers's module.
This is like a list except that you can interleave effects between
each list element. For example:
stdin :: ListT IO String
stdin = ListT (do
eof <- System.IO.isEOF
if eof
then return Nil
else do
line <- getLine
return (Cons line stdin) )
The mnemonic is "List Transformer" because this type takes a base
Monad,
'm', and returns a new transformed
Monad
that adds support for list comprehensions
Not on Stackage, so not searched.
List transformer