Skip to content

Commit

Permalink
Add a note about MonadReader and ParserK
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Oct 31, 2024
1 parent 4e22e5a commit f8e8e54
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/src/Streamly/Internal/Data/ParserK/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ import qualified Streamly.Internal.Data.MutArray.Generic as GenArr
import qualified Streamly.Internal.Data.Array.Generic as GenArr
import qualified Streamly.Internal.Data.Parser.Type as ParserD

-------------------------------------------------------------------------------
-- Developer Notes
-------------------------------------------------------------------------------

-- MonadReader cannot be implemented using continuations for ParserK
--
-- "local" (and hence "MonadReader") cannot be implemented for ParserK because
-- there is no way to override all continuations.
--
-- We can implement `MonadReader` for ParserK via ParserD:
--
-- @
-- instance (Show r, MonadReader r m) => MonadReader r (Parser a m) where
-- {-# INLINE ask #-}
-- ask = Parser.fromEffect ask
-- {-# INLINE local #-}
-- local f (Parser step initial extract) =
-- Parser
-- ((local f .) . step)
-- (local f initial)
-- (local f . extract)
--
-- instance (Show r, MonadReader r m) => MonadReader r (ParserK a m) where
-- {-# INLINE ask #-}
-- ask = ParserK.fromEffect ask
-- {-# INLINE local #-}
-- local f parser = ParserK.adapt $ local f $ ParserK.toParser parser
-- @

-------------------------------------------------------------------------------
-- Types
-------------------------------------------------------------------------------

-- Note: We cannot use an Array directly as input because we need to identify
-- the end of input case using None. We cannot do that using nil Array as nil
-- Arrays can be encountered in normal input as well.
Expand Down

0 comments on commit f8e8e54

Please sign in to comment.