-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple bidirectional serialization and deserialization -- -- Bidirectional serialization based on -- https://blog.poisson.chat/posts/2017-01-01-monadic-profunctors.html @package bidirectional @version 0.1.0.0 -- | Let's assume we have a parser like the following -- --
-- int :: Parser (ReaderT String Maybe) (Writer [Int]) Int Int -- int = parser (ReaderT readMaybe) (x -> x <$ tell [show x]) ---- -- Then you can use the parser for parsing: -- --
-- > runReaderT (decode int) "3" -- Just 3 ---- -- Or for encoding: -- --
-- > execWriter (encode int 3) -- ["3"] ---- -- Or combine both of them -- --
-- > runReaderT (decode int) $ head $ execWriter $ encode int 3 -- Just 3 --module Data.IParser -- | The core bidirectional parser type -- -- See the module for usage example data IParser r w c a IParser :: r a -> Star w c a -> IParser r w c a -- | Return a value "a" in context "r". [decoder] :: IParser r w c a -> r a -- | Generate a value "a" from the initial object "c" in the context "w" [encoder] :: IParser r w c a -> Star w c a -- | Smart constructor for the parser parser :: r a -> (c -> w a) -> IParser r w c a -- | Extract the decoder from the parser decode :: IParser r w c a -> r a -- | Extract the encoder from the parser encode :: IParser r w c a -> c -> w a -- | Record accessor helper -- -- Due to the nature of the parser, the encoder gets the full record -- type, when it should only focus on a specific part. -- --
-- data Person = Person { name :: String, age :: Int }
--
-- person :: IParser r w Person Person
-- person =
-- Person $ name .= string
-- * age .= int
--
(.=) :: (Functor r, Functor w) => (c -> c') -> IParser r w c' a -> IParser r w c a
instance (GHC.Base.Functor w, GHC.Base.Functor r) => GHC.Base.Functor (Data.IParser.IParser r w c)
instance (GHC.Base.Applicative w, GHC.Base.Applicative r) => GHC.Base.Applicative (Data.IParser.IParser r w c)
instance (GHC.Base.Functor r, GHC.Base.Functor w) => Data.Profunctor.Unsafe.Profunctor (Data.IParser.IParser r w)