Skip to content

Commit f8e8e54

Browse files
committed
Add a note about MonadReader and ParserK
1 parent 4e22e5a commit f8e8e54

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

  • core/src/Streamly/Internal/Data/ParserK

core/src/Streamly/Internal/Data/ParserK/Type.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ import qualified Streamly.Internal.Data.MutArray.Generic as GenArr
6262
import qualified Streamly.Internal.Data.Array.Generic as GenArr
6363
import qualified Streamly.Internal.Data.Parser.Type as ParserD
6464

65+
-------------------------------------------------------------------------------
66+
-- Developer Notes
67+
-------------------------------------------------------------------------------
68+
69+
-- MonadReader cannot be implemented using continuations for ParserK
70+
--
71+
-- "local" (and hence "MonadReader") cannot be implemented for ParserK because
72+
-- there is no way to override all continuations.
73+
--
74+
-- We can implement `MonadReader` for ParserK via ParserD:
75+
--
76+
-- @
77+
-- instance (Show r, MonadReader r m) => MonadReader r (Parser a m) where
78+
-- {-# INLINE ask #-}
79+
-- ask = Parser.fromEffect ask
80+
-- {-# INLINE local #-}
81+
-- local f (Parser step initial extract) =
82+
-- Parser
83+
-- ((local f .) . step)
84+
-- (local f initial)
85+
-- (local f . extract)
86+
--
87+
-- instance (Show r, MonadReader r m) => MonadReader r (ParserK a m) where
88+
-- {-# INLINE ask #-}
89+
-- ask = ParserK.fromEffect ask
90+
-- {-# INLINE local #-}
91+
-- local f parser = ParserK.adapt $ local f $ ParserK.toParser parser
92+
-- @
93+
94+
-------------------------------------------------------------------------------
95+
-- Types
96+
-------------------------------------------------------------------------------
97+
6598
-- Note: We cannot use an Array directly as input because we need to identify
6699
-- the end of input case using None. We cannot do that using nil Array as nil
67100
-- Arrays can be encountered in normal input as well.

0 commit comments

Comments
 (0)