| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Control.Monad.Loop.Internal
Synopsis
- newtype LoopT (m :: k -> Type) a = LoopT {
- runLoopT :: forall (r :: k). (a -> m r -> m r -> m r) -> m r -> m r -> m r
- type Loop = LoopT Identity
- loop :: Loop a -> Loop a
- data Unroll (n :: Nat) = Unroll
- type family UnTL (n :: Nat) :: Nat where ...
- class Unrolling (n :: Nat)
- noUnroll :: Unroll 1
- cons :: forall {k} a (m :: k -> Type). a -> LoopT m a -> LoopT m a
- continue :: forall {k} a (m :: k -> Type). a -> LoopT m a
- continue_ :: forall {k} (m :: k -> Type) a. LoopT m a
- break_ :: forall {k} (m :: k -> Type) a. LoopT m a
- exec_ :: Applicative m => LoopT m a -> m ()
- iterate :: forall {k} (n :: Nat) a (m :: k -> Type). Unrolling (UnTL n) => Unroll n -> a -> (a -> a) -> LoopT m a
- forever :: forall {k} (n :: Nat) (m :: k -> Type). Unrolling (UnTL n) => Unroll n -> LoopT m ()
- for :: forall {k} (n :: Nat) a (m :: k -> Type). Unrolling (UnTL n) => Unroll n -> a -> (a -> Bool) -> (a -> a) -> LoopT m a
- unfoldl :: forall {k} (n :: Nat) i a (m :: k -> Type). Unrolling (UnTL n) => Unroll n -> (i -> Maybe (i, a)) -> i -> LoopT m a
- while :: forall (n :: Nat) m. (Unrolling (UnTL n), Monad m) => Unroll n -> m Bool -> LoopT m ()
Documentation
newtype LoopT (m :: k -> Type) a Source #
LoopT m a represents a loop over a base type m that yields a value
a at each iteration. It can be used as a monad transformer, but there
are actually no restrictions on the type m. However, this library only
provides functions to execute the loop if m is at least Applicative
(for exec_). If m is also Foldable, so is LoopT m. For any other
type, you may use runLoopT.
Instances
| MonadTrans (LoopT :: (Type -> Type) -> Type -> Type) Source # | |||||||||
Defined in Control.Monad.Loop.Internal | |||||||||
| MonadIO m => MonadIO (LoopT m) Source # | |||||||||
Defined in Control.Monad.Loop.Internal | |||||||||
| (Applicative m, Foldable m) => Foldable (LoopT m) Source # | |||||||||
Defined in Control.Monad.Loop.Internal Methods fold :: Monoid m0 => LoopT m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> LoopT m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> LoopT m a -> m0 # foldr :: (a -> b -> b) -> b -> LoopT m a -> b # foldr' :: (a -> b -> b) -> b -> LoopT m a -> b # foldl :: (b -> a -> b) -> b -> LoopT m a -> b # foldl' :: (b -> a -> b) -> b -> LoopT m a -> b # foldr1 :: (a -> a -> a) -> LoopT m a -> a # foldl1 :: (a -> a -> a) -> LoopT m a -> a # elem :: Eq a => a -> LoopT m a -> Bool # maximum :: Ord a => LoopT m a -> a # minimum :: Ord a => LoopT m a -> a # | |||||||||
| (Applicative m, Foldable m) => Traversable (LoopT m) Source # | |||||||||
Defined in Control.Monad.Loop.Internal | |||||||||
| Applicative (LoopT m) Source # | |||||||||
| Functor (LoopT m) Source # | |||||||||
| Monad (LoopT m) Source # | |||||||||
| Monad m => ForEach (LoopT m) (Vector a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (Monad m, Prim a) => ForEach (LoopT m) (Vector a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (Monad m, Storable a) => ForEach (LoopT m) (Vector a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (Monad m, Unbox a) => ForEach (LoopT m) (Vector a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| Monad m => ForEach (LoopT m) [a] Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (PrimMonad m, PrimState m ~ s) => ForEach (LoopT m) (MVector s a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (PrimMonad m, Prim a, PrimState m ~ s) => ForEach (LoopT m) (MVector s a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (Storable a, PrimMonad m, PrimState m ~ s) => ForEach (LoopT m) (MVector s a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
| (PrimMonad m, Unbox a, PrimState m ~ s) => ForEach (LoopT m) (MVector s a) Source # | |||||||||
Defined in Control.Monad.Loop.ForEach Associated Types
| |||||||||
loop :: Loop a -> Loop a Source #
loop is just an aid to type inference. For loops over a base monad,
there are usually other constraints that fix the type, but for pure
loops, the compiler often has trouble inferring Identity.
data Unroll (n :: Nat) Source #
Proxy type for GHC's type level literal natural numbers. n is the
number of times the loop will be unrolled into its own body.
Constructors
| Unroll |
continue :: forall {k} a (m :: k -> Type). a -> LoopT m a Source #
Yield a value for this iteration of the loop and skip immediately to the next iteration.
continue_ :: forall {k} (m :: k -> Type) a. LoopT m a Source #
Skip immediately to the next iteration of the loop without yielding a value.
break_ :: forall {k} (m :: k -> Type) a. LoopT m a Source #
Skip all the remaining iterations of the immediately-enclosing loop.
exec_ :: Applicative m => LoopT m a -> m () Source #
Execute a loop, sequencing the effects and discarding the values.
Arguments
| :: forall {k} (n :: Nat) a (m :: k -> Type). Unrolling (UnTL n) | |
| => Unroll n | Unrolling factor |
| -> a | Starting value of iterator |
| -> (a -> a) | Advance the iterator |
| -> LoopT m a |
Iterate forever (or until break is used).
forever :: forall {k} (n :: Nat) (m :: k -> Type). Unrolling (UnTL n) => Unroll n -> LoopT m () Source #
Loop forever without yielding (interesting) values.
Arguments
| :: forall {k} (n :: Nat) a (m :: k -> Type). Unrolling (UnTL n) | |
| => Unroll n | Unrolling factor |
| -> a | Starting value of iterator |
| -> (a -> Bool) | Termination condition. The loop will terminate the first time this is false. The termination condition is checked at the start of each iteration. |
| -> (a -> a) | Advance the iterator |
| -> LoopT m a |
Standard for loop.