-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An alternative to monads -- -- Please see the README on GitHub at -- https://github.com/Atry/do-notation-dsl#readme @package do-notation-dsl @version 0.1.0.3 module Control.Dsl.Cont type r !! a = (a -> r) -> r newtype Cont r a Cont :: (r !! a) -> Cont r a when :: () => Bool -> r !! () -> Cont r () module Control.Dsl.Do class Do k r a (>>=) :: Do k r a => k r a -> r !! a (>>) :: Do k r a => k r a -> r -> r instance Control.Dsl.Dsl.Dsl k r a => Control.Dsl.Do.Do k r a instance Control.Dsl.Do.Do Control.Dsl.Cont.Cont r a module Control.Dsl.Empty data Empty r a [Empty] :: Empty r Void empty :: Dsl Empty r Void => r instance Control.Dsl.Dsl.Dsl Control.Dsl.Empty.Empty [r] Data.Void.Void instance Control.Dsl.Dsl.Dsl Control.Dsl.Empty.Empty (GHC.Base.Maybe r) Data.Void.Void module Control.Dsl.Monadic newtype Monadic m r a Monadic :: (m a) -> Monadic m r a instance GHC.Base.Monad m => Control.Dsl.Dsl.Dsl (Control.Dsl.Monadic.Monadic m) (m b) a module Control.Dsl.Return data Return r0 r b [Return] :: r0 -> Return r0 r Void return :: Dsl Return r0 r Void => r0 -> r instance Control.Dsl.Dsl.Dsl (Control.Dsl.Return.Return r) r Data.Void.Void instance Control.Dsl.Dsl.Dsl (Control.Dsl.Return.Return a) (r Control.Dsl.Cont.!! a) Data.Void.Void instance Control.Dsl.Dsl.Dsl (Control.Dsl.Return.Return r) [r] Data.Void.Void instance Control.Dsl.Dsl.Dsl (Control.Dsl.Return.Return r) (GHC.Base.Maybe r) Data.Void.Void instance Control.Dsl.Dsl.Dsl (Control.Dsl.Return.Return r) (GHC.Types.IO r) Data.Void.Void module Control.Dsl.Shift -- |
-- >>> :set -XTypeOperators -- -- >>> :set -XRebindableSyntax -- -- >>> import Prelude hiding ((>>), (>>=), return) -- -- >>> import Control.Dsl -- -- >>> import Control.Dsl.Return -- -- >>> import Control.Dsl.Yield -- -- >>> import Control.Dsl.Empty ---- --
-- >>> :{
-- earlyGenerator :: Bool -> [String] !! Integer
-- earlyGenerator earlyReturn = do
-- Yield "inside earlyGenerator"
-- when earlyReturn $ do
-- Yield "early return"
-- return 1
-- Yield "normal return"
-- return 0
-- :}
--
--
--
-- >>> :{
-- earlyGeneratorTest :: [String]
-- earlyGeneratorTest = do
-- Yield "before earlyGenerator"
-- i <- Shift $ earlyGenerator True
-- Yield "after earlyGenerator"
-- Yield $ "the return value of earlyGenerator is " ++ show i
-- empty
-- :}
--
--
-- -- >>> earlyGeneratorTest -- ["before earlyGenerator","inside earlyGenerator","early return","after earlyGenerator","the return value of earlyGenerator is 1"] --newtype Shift r0 r a Shift :: (r0 !! a) -> Shift r0 r a instance Control.Dsl.Dsl.Dsl (Control.Dsl.Shift.Shift r) r a -- |
-- >>> :set -XTypeFamilies -- -- >>> :set -XMultiParamTypeClasses -- -- >>> :set -XFlexibleInstances -- -- >>> :set -XFlexibleContexts -- -- >>> :set -XRebindableSyntax -- -- >>> :set -XTypeApplications -- -- >>> import qualified Prelude -- -- >>> import Prelude hiding ((>>), (>>=), return) -- -- >>> import Control.Dsl -- -- >>> import Control.Dsl.State -- -- >>> import Control.Dsl.Yield -- -- >>> import Control.Dsl.Return -- -- >>> import Data.Void ---- --
-- >>> :{
-- f = do
-- Yield "foo"
-- config <- Get @Bool
-- when config $ do
-- Yield "bar"
-- return ()
-- return "baz"
-- :}
--
--
-- -- >>> :type f -- f :: (Dsl (Yield [Char]) r (), Dsl (Return [Char]) r Void, -- Dsl Get r Bool) => -- r ---- --
-- >>> f True :: [String] -- ["foo","bar","baz"] ---- --
-- >>> f False :: [String] -- ["foo","baz"] ---- --
-- >>> :{
-- instance Dsl (Yield String) (IO ()) () where
-- cpsApply (Yield a) = (Prelude.>>=) (putStrLn $ "Yield " ++ a)
-- :}
--
--
--
-- >>> :{
-- instance Dsl Get (IO ()) Bool where
-- cpsApply Get f = (putStrLn "Get") Prelude.>> f False
-- :}
--
--
--
-- >>> :{
-- instance Dsl (Return String) (IO ()) Void where
-- cpsApply (Return a) _ = putStrLn $ "Return " ++ a
-- :}
--
--
-- -- >>> f :: IO () -- Yield foo -- Get -- Return baz --module Control.Dsl -- | This type class witnesses a use case of k, which is an ad-hoc -- delimited continuation adaptive to the answer type r. class Dsl k r a cpsApply :: Dsl k r a => k r0 a -> r !! a return :: Dsl Return r0 r Void => r0 -> r (>>=) :: Do k r a => k r a -> r !! a (>>) :: Do k r a => k r a -> r -> r when :: () => Bool -> r !! () -> Cont r () -- | This module provides the ability to Put and Get the -- value of multiple mutable variables in a do block. -- --
-- >>> :set -XTypeApplications -- -- >>> :set -XRebindableSyntax -- -- >>> import Prelude hiding ((>>), (>>=), return) -- -- >>> import Control.Dsl -- -- >>> import Data.Sequence ---- --
-- >>> :set -fprint-potential-instances
--
-- >>> :{
-- formatter :: Double -> Integer -> Seq String -> String
-- formatter = do
-- --
-- -- Equivalent of `!Put(!Get[Vector[Any]] :+ "x=")` in Dsl.scala
-- tmpBuffer0 <- Get @(Seq String)
-- Put $ tmpBuffer0 |> "x="
-- --
-- -- Equivalent of `!Put(!Get[Vector[Any]] :+ !Get[Double])` in Dsl.scala
-- tmpBuffer1 <- Get @(Seq String)
-- d <- Get @Double
-- Put $ tmpBuffer1 |> show d
-- --
-- -- Equivalent of `!Put(!Get[Vector[Any]] :+ ",y=")` in Dsl.scala
-- tmpBuffer2 <- Get @(Seq String)
-- Put $ tmpBuffer2 |> ",y="
-- --
-- -- Equivalent of `!Put(!Get[Vector[Any]] :+ !Get[Int])` in Dsl.scala
-- tmpBuffer3 <- Get @(Seq String)
-- i <- Get @Integer
-- Put $ tmpBuffer3 |> show i
-- --
-- -- Equivalent of `!Return((!Get[Vector[Any]]).mkString)` in Dsl.scala
-- tmpBuffer4 <- Get @(Seq String)
-- return $ foldl1 (++) tmpBuffer4
-- :}
--
--
-- -- >>> formatter 0.5 42 Empty -- "x=0.5,y=42" --module Control.Dsl.State type State a b = a -> b data Put a r u [Put] :: a -> Put a r () data Get r a [Get] :: forall a r. Get r a instance Control.Dsl.Dsl.Dsl Control.Dsl.State.Get (Control.Dsl.State.State a b) a instance Control.Dsl.Dsl.Dsl (Control.Dsl.State.Put a) (Control.Dsl.State.State a b) () -- | This module contains the Yield data type and related Dsl -- instances. -- -- The Yield data type can be used to create generators, similar -- to the yield keyword in C#, Python, and ECMAScript. -- --
-- >>> :set -XTypeApplications
--
-- >>> :set -XRebindableSyntax
--
-- >>> import Prelude hiding ((>>), (>>=), return)
--
-- >>> import Control.Dsl
--
-- >>> import Data.Word
--
-- >>> import Data.Bits
--
-- >>> :{
-- randomGenerator :: Word32 -> [Word32]
-- randomGenerator seed =
-- do let tmp1 = xor seed $ shiftL seed 13
-- let tmp2 = xor tmp1 $ shiftR tmp1 17
-- let tmp3 = xor tmp2 $ shiftL tmp2 5
-- Yield tmp3
-- randomGenerator tmp3
-- :}
--
--
-- -- >>> take 5 $ randomGenerator 2463534242 -- [723471715,2497366906,2064144800,2008045182,3532304609] --module Control.Dsl.Yield data Yield a r b [Yield] :: a -> Yield a r () instance Control.Dsl.Dsl.Dsl (Control.Dsl.Yield.Yield a) [a] ()