-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Classes to handle Prelude style IO functions for different datatypes -- -- The functions in the Prelude such as "getContents", "putStr" only work -- for plain Strings. -- -- There are similar functions in ByteString for reading and -- writing, as well as Text. -- -- This requires one to import the appropriate functions, usually -- qualified, for the particular datatype one is using. Changing the -- datatype at the very least involves changing import statements across -- your program. -- -- The package introduces classes to overload functions like -- "getContents", "putStr" over multiple datatypes, so implementations -- can be changed easily. -- -- All the code documentation is in System.IO.StringLike.Impl. -- -- All the other modules are just re-exports. @package io-string-like @version 0.1.0.0 -- | The classes in this library roughly encapulates things you can read or -- write through a "handle", typically writing something "string like" to -- a file, but the interface is very flexible. -- -- Currently only String, ByteString and Text in -- their strict/lazy varieties and builders are implemented. -- -- However, the interface has the flexibility to write non-character -- data. For example an implementation for a [Int] could just -- write all the Ints in binary to the file and read them back -- into a [Int]. -- -- Also the interface can be defined for "handles" other than standard -- files. Currently the only such instance that does not use -- Handle is for hGetContents, where one can call directly: -- --
--   hGetContents fileName
--   
-- -- In this case, "handle" is a FilePath. -- -- The initial motivation of to avoid having to change all your function -- calls if you change your string type, but it's actually more general -- than that now. -- -- The point of this library is to be able to read and write raw data to -- the disk (and perhaps other places) quickly without thinking too much -- about it. -- -- It's not intended to be a replacement for say Binary. It's -- intended to be lower level. Binary internally creates lazy -- bytestrings for the user to write to the disk, this library is instead -- just about directly writing raw data. -- -- Note that we currently only have classes for -- -- Most of the functions should be fairly self explanatory having the -- same meaning as in Prelude or System.IO but more -- general. module System.IO.StringLike.Impl -- | CanGetContents if effectively the following type synonym, for -- the common case of an ordinary Handle in the IO monad -- like so. -- --
--   type CanGetContents t = CanGetContentsClass IO Handle t
--   
-- -- The reason why it's defined as a class with a catch all instance -- instead is so modules which use CanGetContents do not have to -- include the language pragma FleixbleContexts. -- -- However, this approach requires this module to use the pragma -- UndecidableInstances, but I figure it's better to add more -- complexity to the library than to clients. -- -- CanGet, CanGetLine, CanPutStr, -- CanPutStrLn all are similar synonyms with the same explanation -- for their definition so I won't repeat myself. class CanGetContentsClass IO Handle t => CanGetContents t class Monad m => CanGetContentsClass m handleT t -- | Generalised hGetContents hGetContents :: CanGetContentsClass m handleT t => handleT -> m t -- | Generalised hGetContents hGetContents :: (CanGetContentsClass m handleT t, CanProxyFrom t, CanGetContentsClass m handleT (CanProxyT t)) => handleT -> m t getContents :: CanGetContents t => IO t readFile :: CanGetContents t => FilePath -> IO t -- | Effective type synonym for CanGetLineClass. See -- CanGetContents for more details. class CanGetLineClass IO Handle t => CanGetLine t class CanGetContentsClass m handleT t => CanGetLineClass m handleT t -- | Generalised hGetLine hGetLine :: CanGetLineClass m handleT t => handleT -> m t -- | Generalised hGetLine hGetLine :: (CanGetLineClass m handleT t, CanProxyFrom t, CanGetLineClass m handleT (CanProxyT t)) => handleT -> m t getLine :: CanGetLine t => IO t -- | Effective type synonym for CanPutStrClass. See -- CanGetContents for more details. class CanPutStrClass IO Handle t => CanPutStr t class Monad m => CanPutStrClass m handleT t -- | Generalised hPutStr hPutStr :: CanPutStrClass m handleT t => handleT -> t -> m () -- | Generalised hPutStr hPutStr :: (CanPutStrClass m handleT t, CanProxyTo t, CanPutStrClass m handleT (CanProxyT t)) => handleT -> t -> m () putStr :: CanPutStr t => t -> IO () writeFile :: CanPutStr t => FilePath -> t -> IO () appendFile :: CanPutStr t => FilePath -> t -> IO () interact :: (CanGetContents t, CanPutStr t) => (t -> t) -> IO () -- | Effective type synonym for CanPutStrLnClass. See -- CanGetContents for more details. class CanPutStrLnClass IO Handle t => CanPutStrLn t class CanPutStrClass m handleT t => CanPutStrLnClass m handleT t -- | Generalised hPutStrLn hPutStrLn :: CanPutStrLnClass m handleT t => handleT -> t -> m () -- | Generalised hPutStrLn hPutStrLn :: (CanPutStrLnClass m handleT t, CanProxyTo t, CanPutStrLnClass m handleT (CanProxyT t)) => handleT -> t -> m () putStrLn :: CanPutStrLn t => t -> IO () -- | If you have a data structure where in many cases the simplest way to -- read or write to it is just convert it to another you should define an -- instance of this class. -- -- For example, the simple way to write ByteString -- Builders is just to convert them to and from lazy -- ByteStrings. -- -- Defining classese CanProxyTo and CanProxyFrom will -- define default methods for many of the other classes in this library. -- These can still be overriden if desired but it will save you a lot of -- boilerplate if you just which to convert your structure through some -- other. class CanProxyTo t -- | How to convert to the type you will attempt to store canProxyTo :: CanProxyTo t => t -> CanProxyT t class CanProxyFrom t -- | How to convert from the type you will attempt to store canProxyFrom :: CanProxyFrom t => CanProxyT t -> t instance System.IO.StringLike.Impl.CanGetContentsClass GHC.Types.IO GHC.IO.Handle.Types.Handle t => System.IO.StringLike.Impl.CanGetContents t instance System.IO.StringLike.Impl.CanGetLineClass GHC.Types.IO GHC.IO.Handle.Types.Handle t => System.IO.StringLike.Impl.CanGetLine t instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle GHC.Base.String instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.ByteString.Internal.ByteString instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString instance System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.ByteString.Builder.Internal.Builder instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Text instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text instance System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text => System.IO.StringLike.Impl.CanGetLineClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Builder.Builder instance (m ~ GHC.Types.IO, System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle t) => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.FilePath t instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle GHC.Base.String instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.ByteString.Internal.ByteString instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString instance (GHC.Base.Monad m, System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString) => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.ByteString.Builder.Internal.Builder instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Text instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text instance (GHC.Base.Monad m, System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text) => System.IO.StringLike.Impl.CanGetContentsClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Builder.Builder instance System.IO.StringLike.Impl.CanProxyFrom Data.ByteString.Builder.Internal.Builder instance System.IO.StringLike.Impl.CanProxyFrom Data.Text.Internal.Builder.Builder instance System.IO.StringLike.Impl.CanPutStrClass GHC.Types.IO GHC.IO.Handle.Types.Handle t => System.IO.StringLike.Impl.CanPutStr t instance System.IO.StringLike.Impl.CanPutStrLnClass GHC.Types.IO GHC.IO.Handle.Types.Handle t => System.IO.StringLike.Impl.CanPutStrLn t instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle GHC.Base.String instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.ByteString.Internal.ByteString instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString instance System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.ByteString.Builder.Internal.Builder => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.ByteString.Builder.Internal.Builder instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Text instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text instance System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text => System.IO.StringLike.Impl.CanPutStrLnClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Builder.Builder instance (m ~ GHC.Types.IO, System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle t) => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.FilePath t instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle GHC.Base.String instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.ByteString.Internal.ByteString instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.ByteString.Lazy.Internal.ByteString instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.ByteString.Builder.Internal.Builder instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Text instance m ~ GHC.Types.IO => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text instance (GHC.Base.Monad m, System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Lazy.Text) => System.IO.StringLike.Impl.CanPutStrClass m GHC.IO.Handle.Types.Handle Data.Text.Internal.Builder.Builder instance System.IO.StringLike.Impl.CanProxyTo Data.ByteString.Builder.Internal.Builder instance System.IO.StringLike.Impl.CanProxyTo Data.Text.Internal.Builder.Builder module System.IO.StringLike.GetContents -- | CanGetContents if effectively the following type synonym, for -- the common case of an ordinary Handle in the IO monad -- like so. -- --
--   type CanGetContents t = CanGetContentsClass IO Handle t
--   
-- -- The reason why it's defined as a class with a catch all instance -- instead is so modules which use CanGetContents do not have to -- include the language pragma FleixbleContexts. -- -- However, this approach requires this module to use the pragma -- UndecidableInstances, but I figure it's better to add more -- complexity to the library than to clients. -- -- CanGet, CanGetLine, CanPutStr, -- CanPutStrLn all are similar synonyms with the same explanation -- for their definition so I won't repeat myself. class CanGetContentsClass IO Handle t => CanGetContents t class Monad m => CanGetContentsClass m handleT t -- | Generalised hGetContents hGetContents :: CanGetContentsClass m handleT t => handleT -> m t -- | Generalised hGetContents hGetContents :: (CanGetContentsClass m handleT t, CanProxyFrom t, CanGetContentsClass m handleT (CanProxyT t)) => handleT -> m t getContents :: CanGetContents t => IO t readFile :: CanGetContents t => FilePath -> IO t interact :: (CanGetContents t, CanPutStr t) => (t -> t) -> IO () module System.IO.StringLike.GetLine -- | Effective type synonym for CanGetLineClass. See -- CanGetContents for more details. class CanGetLineClass IO Handle t => CanGetLine t class CanGetContentsClass m handleT t => CanGetLineClass m handleT t -- | Generalised hGetLine hGetLine :: CanGetLineClass m handleT t => handleT -> m t -- | Generalised hGetLine hGetLine :: (CanGetLineClass m handleT t, CanProxyFrom t, CanGetLineClass m handleT (CanProxyT t)) => handleT -> m t getLine :: CanGetLine t => IO t module System.IO.StringLike.PutStr -- | Effective type synonym for CanPutStrClass. See -- CanGetContents for more details. class CanPutStrClass IO Handle t => CanPutStr t class Monad m => CanPutStrClass m handleT t -- | Generalised hPutStr hPutStr :: CanPutStrClass m handleT t => handleT -> t -> m () -- | Generalised hPutStr hPutStr :: (CanPutStrClass m handleT t, CanProxyTo t, CanPutStrClass m handleT (CanProxyT t)) => handleT -> t -> m () putStr :: CanPutStr t => t -> IO () writeFile :: CanPutStr t => FilePath -> t -> IO () appendFile :: CanPutStr t => FilePath -> t -> IO () interact :: (CanGetContents t, CanPutStr t) => (t -> t) -> IO () module System.IO.StringLike.PutStrLn -- | Effective type synonym for CanPutStrLnClass. See -- CanGetContents for more details. class CanPutStrLnClass IO Handle t => CanPutStrLn t class CanPutStrClass m handleT t => CanPutStrLnClass m handleT t -- | Generalised hPutStrLn hPutStrLn :: CanPutStrLnClass m handleT t => handleT -> t -> m () -- | Generalised hPutStrLn hPutStrLn :: (CanPutStrLnClass m handleT t, CanProxyTo t, CanPutStrLnClass m handleT (CanProxyT t)) => handleT -> t -> m () putStrLn :: CanPutStrLn t => t -> IO ()