Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | Safe
Language | Haskell2010

Agda.Utils.ListT

Contents

- List operations
- Monadic list operations.

Description

`ListT` done right, see https://www.haskell.org/haskellwiki/ListT_done_right_alternative

There is also the `list-t` package on hackage (Nikita Volkov) but it again depends on other packages we do not use yet, so we rather implement the few bits we need afresh.

Synopsis

- newtype ListT m a = ListT {
  - runListT :: m (Maybe (a, ListT m a))
  }
- nilListT :: Monad m => ListT m a
- consListT :: Monad m => a -> ListT m a -> ListT m a
- sgListT :: Monad m => a -> ListT m a
- caseListT :: Monad m => ListT m a -> m b -> (a -> ListT m a -> m b) -> m b
- foldListT :: Monad m => (a -> m b -> m b) -> m b -> ListT m a -> m b
- concatListT :: Monad m => ListT m (ListT m a) -> ListT m a
- runMListT :: Monad m => m (ListT m a) -> ListT m a
- consMListT :: Monad m => m a -> ListT m a -> ListT m a
- sgMListT :: Monad m => m a -> ListT m a
- mapMListT :: Monad m => (a -> m b) -> ListT m a -> ListT m b
- mapMListT_alt :: Monad m => (a -> m b) -> ListT m a -> ListT m b
- liftListT :: (Monad m, Monad m') => (forall a. m a -> m' a) -> ListT m a -> ListT m' a

# Documentation

newtype ListT m a #

Lazy monadic computation of a list of results.

Constructors

ListT |
Fields runListT :: m (Maybe (a, ListT m a))

Instances

MonadTrans ListT # |
Methods lift :: Monad m => m a -> ListT m a #
(Applicative m, MonadReader r m) => MonadReader r (ListT m) # |
Methods ask :: ListT m r # local :: (r -> r) -> ListT m a -> ListT m a # reader :: (r -> a) -> ListT m a #
(Applicative m, MonadState s m) => MonadState s (ListT m) # |
Methods get :: ListT m s # put :: s -> ListT m () # state :: (s -> (a, s)) -> ListT m a #
(Functor m, Applicative m, Monad m) => Monad (ListT m) # |
Methods (>>=) :: ListT m a -> (a -> ListT m b) -> ListT m b # (>>) :: ListT m a -> ListT m b -> ListT m b # return :: a -> ListT m a # fail :: String -> ListT m a #
Functor m => Functor (ListT m) # |
Methods fmap :: (a -> b) -> ListT m a -> ListT m b # (<$) :: a -> ListT m b -> ListT m a #
(Functor m, Applicative m, Monad m) => Applicative (ListT m) # |
Methods pure :: a -> ListT m a # (<*>) :: ListT m (a -> b) -> ListT m a -> ListT m b # (*>) :: ListT m a -> ListT m b -> ListT m b # (<*) :: ListT m a -> ListT m b -> ListT m a #
(Applicative m, MonadIO m) => MonadIO (ListT m) # |
Methods liftIO :: IO a -> ListT m a #
(Functor m, Applicative m, Monad m) => Alternative (ListT m) # |
Methods empty :: ListT m a # (<|>) :: ListT m a -> ListT m a -> ListT m a # some :: ListT m a -> ListT m [a] # many :: ListT m a -> ListT m [a] #
(Functor m, Applicative m, Monad m) => MonadPlus (ListT m) # |
Methods mzero :: ListT m a # mplus :: ListT m a -> ListT m a -> ListT m a #
MonadTCM tcm => MonadTCM (ListT tcm) # |
Methods liftTCM :: TCM a -> ListT tcm a #
Monad m => Semigroup (ListT m a) # |
Methods (<>) :: ListT m a -> ListT m a -> ListT m a # sconcat :: NonEmpty (ListT m a) -> ListT m a # stimes :: Integral b => b -> ListT m a -> ListT m a #
Monad m => Monoid (ListT m a) # |
Methods mempty :: ListT m a # mappend :: ListT m a -> ListT m a -> ListT m a # mconcat :: [ListT m a] -> ListT m a #

# List operations

nilListT :: Monad m => ListT m a #

The empty lazy list.

consListT :: Monad m => a -> ListT m a -> ListT m a #

Consing a value to a lazy list.

sgListT :: Monad m => a -> ListT m a #

Singleton lazy list.

caseListT :: Monad m => ListT m a -> m b -> (a -> ListT m a -> m b) -> m b #

Case distinction over lazy list.

foldListT :: Monad m => (a -> m b -> m b) -> m b -> ListT m a -> m b #

Folding a lazy list, effects left-to-right.

concatListT :: Monad m => ListT m (ListT m a) -> ListT m a #

The join operation of the `ListT m` monad.

# Monadic list operations.

runMListT :: Monad m => m (ListT m a) -> ListT m a #

We can ``run'` a computation of a `ListT` as it is monadic itself.

consMListT :: Monad m => m a -> ListT m a -> ListT m a #

Monadic cons.

sgMListT :: Monad m => m a -> ListT m a #

Monadic singleton.

mapMListT :: Monad m => (a -> m b) -> ListT m a -> ListT m b #

Extending a monadic function to `ListT`.

mapMListT_alt :: Monad m => (a -> m b) -> ListT m a -> ListT m b #

Alternative implementation using `foldListT`.

liftListT :: (Monad m, Monad m') => (forall a. m a -> m' a) -> ListT m a -> ListT m' a #

Change from one monad to another