From 404fe2f2bcdeb78b75724deb6e1ae4f2c6228333 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:36:28 -0800 Subject: [PATCH 1/9] Add missing Haddock escape. --- src/Control/Monad/Freer.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Monad/Freer.hs b/src/Control/Monad/Freer.hs index b21d236..f4f0650 100644 --- a/src/Control/Monad/Freer.hs +++ b/src/Control/Monad/Freer.hs @@ -86,7 +86,7 @@ implemented in-memory in terms of 'Control.Monad.Freer.State.State'. With runInMemoryFileSystem :: [('FilePath', 'String')] -> 'Eff' (FileSystem ': effs) '~>' 'Eff' effs runInMemoryFileSystem initVfs = 'Control.Monad.Freer.State.evalState' initVfs '.' fsToState where fsToState :: 'Eff' (FileSystem ': effs) '~>' 'Eff' ('Control.Monad.Freer.State.State' [('FilePath', 'String')] ': effs) - fsToState = 'reinterpret' '$' \case + fsToState = 'reinterpret' '$' \\case ReadFile path -> 'Control.Monad.Freer.State.get' '>>=' \\vfs -> case 'lookup' path vfs of 'Just' contents -> 'pure' contents 'Nothing' -> 'error' ("readFile: no such file " ++ path) From 57d4aa8a0a1624968d1bf5dad965abebc5c8bf48 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:40:51 -0800 Subject: [PATCH 2/9] Fix 'nondeterministic' typo. --- src/Control/Monad/Freer/Internal.hs | 2 +- src/Control/Monad/Freer/NonDet.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Control/Monad/Freer/Internal.hs b/src/Control/Monad/Freer/Internal.hs index de96a4c..fb7e3fc 100644 --- a/src/Control/Monad/Freer/Internal.hs +++ b/src/Control/Monad/Freer/Internal.hs @@ -356,7 +356,7 @@ raise = loop -- Nondeterministic Choice -- -------------------------------------------------------------------------------- --- | A data type for representing nondeterminstic choice. +-- | A data type for representing nondeterministic choice. data NonDet a where MZero :: NonDet a MPlus :: NonDet Bool diff --git a/src/Control/Monad/Freer/NonDet.hs b/src/Control/Monad/Freer/NonDet.hs index 4b4397d..d2de7aa 100644 --- a/src/Control/Monad/Freer/NonDet.hs +++ b/src/Control/Monad/Freer/NonDet.hs @@ -28,7 +28,7 @@ import Control.Monad.Freer.Internal , tsingleton ) --- | A handler for nondeterminstic effects. +-- | A handler for nondeterministic effects. makeChoiceA :: Alternative f => Eff (NonDet ': effs) a From bcc42e85906d35c7f6c78b1d47e1ce0731141e79 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:41:48 -0800 Subject: [PATCH 3/9] Fix 'a' typo. --- src/Control/Monad/Freer/Reader.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Monad/Freer/Reader.hs b/src/Control/Monad/Freer/Reader.hs index 6c661b8..d0959dc 100644 --- a/src/Control/Monad/Freer/Reader.hs +++ b/src/Control/Monad/Freer/Reader.hs @@ -41,7 +41,7 @@ data Reader r a where ask :: forall r effs. Member (Reader r) effs => Eff effs r ask = send Ask --- | Request a value of the environment, and apply as selector\/projection +-- | Request a value of the environment, and apply a selector\/projection -- function to it. asks :: forall r effs a From f5f547981acfb54a3a3cb04011db30e7d0a8c718 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:45:18 -0800 Subject: [PATCH 4/9] Tweak 'Reader' docs. --- src/Control/Monad/Freer/Reader.hs | 113 +++++++++++++++--------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/src/Control/Monad/Freer/Reader.hs b/src/Control/Monad/Freer/Reader.hs index d0959dc..1358df7 100644 --- a/src/Control/Monad/Freer/Reader.hs +++ b/src/Control/Monad/Freer/Reader.hs @@ -72,66 +72,65 @@ local f m = do -- -- In this example the 'Reader' effect provides access to variable bindings. -- Bindings are a @Map@ of integer variables. The variable @count@ contains --- number of variables in the bindings. You can see how to run a Reader effect --- and retrieve data from it with 'runReader', how to access the Reader data --- with 'ask' and 'asks'. +-- the number of variables in the bindings. You can see how to run a @Reader@ +-- effect and retrieve data from it with 'runReader', and how to access the +-- @Reader@ data with 'ask' and 'asks'. -- --- > import Control.Monad.Freer --- > import Control.Monad.Freer.Reader --- > import Data.Map as Map --- > import Data.Maybe --- > --- > type Bindings = Map String Int --- > --- > -- Returns True if the "count" variable contains correct bindings size. --- > isCountCorrect :: Bindings -> Bool --- > isCountCorrect bindings = run $ runReader bindings calc_isCountCorrect --- > --- > -- The Reader effect, which implements this complicated check. --- > calc_isCountCorrect :: Eff '[Reader Bindings] Bool --- > calc_isCountCorrect = do --- > count <- asks (lookupVar "count") --- > bindings <- (ask :: Eff '[Reader Bindings] Bindings) --- > return (count == (Map.size bindings)) --- > --- > -- The selector function to use with 'asks'. --- > -- Returns value of the variable with specified name. --- > lookupVar :: String -> Bindings -> Int --- > lookupVar name bindings = fromJust (Map.lookup name bindings) --- > --- > sampleBindings :: Map.Map String Int --- > sampleBindings = Map.fromList [("count",3), ("1",1), ("b",2)] --- > --- > main :: IO () --- > main = putStrLn --- > $ "Count is correct for bindings " ++ show sampleBindings ++ ": " --- > ++ show (isCountCorrect sampleBindings) +-- @ +-- import Control.Monad.Freer +-- import Control.Monad.Freer.Reader +-- import Data.Map (Map, (!)) +-- import qualified Data.Map as Map +-- +-- type Bindings = Map String Int +-- +-- -- Returns whether the "count" variable contains the correct bindings size. +-- isCountCorrect :: Bindings -> Bool +-- isCountCorrect bindings = run $ 'runReader' bindings checkCount +-- +-- -- The Reader effect, which implements this complicated check. +-- checkCount :: 'Eff' \'['Reader' Bindings] Bool +-- checkCount = do +-- count <- 'asks' (lookupVar "count") +-- bindings <- ('ask' :: Eff \'[Reader Bindings] Bindings) +-- return (count == Map.size bindings) +-- +-- -- The selector function to use with 'asks'. +-- -- Returns the value of the variable with specified name. +-- lookupVar :: String -> Bindings -> Int +-- lookupVar name bindings = bindings ! name +-- +-- sampleBindings :: Bindings +-- sampleBindings = Map.fromList [("count", 3), ("1", 1), ("b", 2)] +-- +-- main :: IO () +-- main = putStrLn +-- $ "Count is correct for bindings " ++ show sampleBindings ++ ": " +-- ++ show (isCountCorrect sampleBindings) +-- @ -- $localExample -- -- Shows how to modify 'Reader' content with 'local'. -- --- > import Control.Monad.Freer --- > import Control.Monad.Freer.Reader --- > --- > import Data.Map as Map --- > import Data.Maybe --- > --- > type Bindings = Map String Int --- > --- > calculateContentLen :: Eff '[Reader String] Int --- > calculateContentLen = do --- > content <- (ask :: Eff '[Reader String] String) --- > return (length content) --- > --- > -- Calls calculateContentLen after adding a prefix to the Reader content. --- > calculateModifiedContentLen :: Eff '[Reader String] Int --- > calculateModifiedContentLen = local ("Prefix " ++) calculateContentLen --- > --- > main :: IO () --- > main = do --- > let s = "12345" --- > let modifiedLen = run $ runReader s calculateModifiedContentLen --- > let len = run $ runReader s calculateContentLen --- > putStrLn $ "Modified 's' length: " ++ (show modifiedLen) --- > putStrLn $ "Original 's' length: " ++ (show len) +-- @ +-- import Control.Monad.Freer +-- import Control.Monad.Freer.Reader +-- +-- calculateContentLen :: 'Eff' \'['Reader' String] Int +-- calculateContentLen = do +-- content <- ('ask' :: Eff \'[Reader String] String) +-- return (length content) +-- +-- -- Calls calculateContentLen after adding a prefix to the Reader content. +-- calculateModifiedContentLen :: Eff \'[Reader String] Int +-- calculateModifiedContentLen = 'local' ("Prefix " ++) calculateContentLen +-- +-- main :: IO () +-- main = do +-- let s = "12345" +-- let modifiedLen = run $ 'runReader' s calculateModifiedContentLen +-- let len = run $ runReader s calculateContentLen +-- putStrLn $ "Modified \'s\' length: " ++ (show modifiedLen) +-- putStrLn $ "Original \'s\' length: " ++ (show len) +-- @ From 976e14072e198d5a790bab8b3100ad76fe18d69c Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:46:28 -0800 Subject: [PATCH 5/9] Add 'NonDet' docs. --- src/Control/Monad/Freer/Internal.hs | 3 +++ src/Control/Monad/Freer/NonDet.hs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/Control/Monad/Freer/Internal.hs b/src/Control/Monad/Freer/Internal.hs index fb7e3fc..091ae85 100644 --- a/src/Control/Monad/Freer/Internal.hs +++ b/src/Control/Monad/Freer/Internal.hs @@ -358,7 +358,10 @@ raise = loop -- | A data type for representing nondeterministic choice. data NonDet a where + -- | Terminates the current branch of the computation. MZero :: NonDet a + -- | Splits the computation into two branches, + -- producing 'True' in one branch and 'False' in the other. MPlus :: NonDet Bool instance Member NonDet effs => Alternative (Eff effs) where diff --git a/src/Control/Monad/Freer/NonDet.hs b/src/Control/Monad/Freer/NonDet.hs index d2de7aa..3ee4f11 100644 --- a/src/Control/Monad/Freer/NonDet.hs +++ b/src/Control/Monad/Freer/NonDet.hs @@ -38,6 +38,8 @@ makeChoiceA = handleRelay (pure . pure) $ \m k -> MZero -> pure empty MPlus -> (<|>) <$> k True <*> k False +-- | Attempt to split the nondeterministic computation into its +-- first result and the remainder of the computation. msplit :: Member NonDet effs => Eff effs a From 9dde7050bec9a6f27b117a70ada5d15fa4cc279d Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:47:25 -0800 Subject: [PATCH 6/9] Fix 'outputting' typo. --- src/Control/Monad/Freer/Trace.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Monad/Freer/Trace.hs b/src/Control/Monad/Freer/Trace.hs index 9e78edb..cfb884f 100644 --- a/src/Control/Monad/Freer/Trace.hs +++ b/src/Control/Monad/Freer/Trace.hs @@ -8,7 +8,7 @@ -- Portability: GHC specific language extensions. -- -- Composable handler for 'Trace' effects. Trace allows one to debug the --- operation of sequences of effects by outputing to the console. +-- operation of sequences of effects by outputting to the console. -- -- Using as a starting point. module Control.Monad.Freer.Trace From 311adab48e7909abb7a69a5fac3c45a46b455c57 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:48:05 -0800 Subject: [PATCH 7/9] Align comment. --- src/Control/Monad/Freer/TH.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Monad/Freer/TH.hs b/src/Control/Monad/Freer/TH.hs index df09d66..aaa26a6 100644 --- a/src/Control/Monad/Freer/TH.hs +++ b/src/Control/Monad/Freer/TH.hs @@ -60,7 +60,7 @@ makeEffect = genFreer True -- -- -- | Output a string. -- output :: Member Lang effs --- => String -- ^ String to output. +-- => String -- ^ String to output. -- -> Eff effs () -- ^ No result. -- @ -- From 9fd630a75b9b5a02f23747a660f08d19d440c467 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:49:22 -0800 Subject: [PATCH 8/9] Add missing articles. --- src/Control/Monad/Freer/State.hs | 4 ++-- src/Control/Monad/Freer/Writer.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Control/Monad/Freer/State.hs b/src/Control/Monad/Freer/State.hs index deadd1a..d63b699 100644 --- a/src/Control/Monad/Freer/State.hs +++ b/src/Control/Monad/Freer/State.hs @@ -12,7 +12,7 @@ -- Composable handler for 'State' effects. Handy for passing an updatable state -- through a computation. -- --- Some computations may not require the full power of 'State' effect: +-- Some computations may not require the full power of the 'State' effect: -- -- * For a read-only state, see "Control.Monad.Freer.Reader". -- * To accumulate a value without using it on the way, see @@ -57,7 +57,7 @@ get = send Get put :: forall s effs. Member (State s) effs => s -> Eff effs () put s = send (Put s) --- | Modify the current state of type @s :: *@ using provided function +-- | Modify the current state of type @s :: *@ using the provided function -- @(s -> s)@. modify :: forall s effs. Member (State s) effs => (s -> s) -> Eff effs () modify f = fmap f get >>= put diff --git a/src/Control/Monad/Freer/Writer.hs b/src/Control/Monad/Freer/Writer.hs index 45a0012..fdde908 100644 --- a/src/Control/Monad/Freer/Writer.hs +++ b/src/Control/Monad/Freer/Writer.hs @@ -10,8 +10,8 @@ -- Portability: GHC specific language extensions. -- -- 'Writer' effects, for writing\/appending values (line count, list of --- messages, etc.) to an output. Current value of 'Writer' effect output is not --- accessible to the computation. +-- messages, etc.) to an output. The current value of the 'Writer' effect output +-- is not accessible to the computation. -- -- Using as a starting point. module Control.Monad.Freer.Writer From ed171f966b01f875aabe6b3b621c40e5eedea983 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Thu, 29 Dec 2022 10:50:12 -0800 Subject: [PATCH 9/9] Use colon instead of hyphen. --- src/Control/Monad/Freer/Writer.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Monad/Freer/Writer.hs b/src/Control/Monad/Freer/Writer.hs index fdde908..c156105 100644 --- a/src/Control/Monad/Freer/Writer.hs +++ b/src/Control/Monad/Freer/Writer.hs @@ -28,7 +28,7 @@ import Data.Monoid ((<>)) import Control.Monad.Freer.Internal (Eff, Member, handleRelay, send) --- | Writer effects - send outputs to an effect environment. +-- | Writer effects: send outputs to an effect environment. data Writer w r where Tell :: w -> Writer w ()