haskeline-0.8.4.0: A command-line interface for user input, written in Haskell.
Safe HaskellNone
LanguageHaskell98

System.Console.Haskeline.ReaderT

Contents

Description

Provides an interface for ReaderT rather than InputT.

Since: 0.8.4.0

Synopsis

ReaderT

These functions expose the InputT type in terms of ordinary ReaderT. This allows for easier integration with applications that do not use a concrete monad transformer stack, or do not want to commit to having InputT in the stack.

toReaderT :: forall (m :: Type -> Type) a. InputT m a -> ReaderT (InputTEnv m) m a Source #

Maps an InputT to a ReaderT. Useful for lifting InputT functions into some other reader-like monad.

Examples:

import System.Console.Haskeline qualified as H

runApp :: ReaderT (InputTEnv IO) IO ()
runApp = do
  input <- toReaderT (H.getInputLine "Enter your name: ")
  ...
-- MTL-style polymorphism
class MonadHaskeline m where
  getInputLine :: String -> m (Maybe String)

-- AppT is the core type over ReaderT.
instance MonadHaskeline (AppT m) where
  getInputLine = lift . toReaderT . H.getInputLine

runApp :: (MonadHaskeline m) => m ()
runApp = do
  input <- getInputLine "Enter your name: "
  ...

Since: 0.8.4.0

fromReaderT :: forall (m :: Type -> Type) a. ReaderT (InputTEnv m) m a -> InputT m a Source #

Maps a ReaderT to an InputT. Allows defining an application in terms of ReaderT.

Examples:

import System.Console.Haskeline qualified as H

-- Could be generalized to MonadReader, effects libraries.
runApp :: ReaderT (InputTEnv IO) IO ()

main :: IO ()
main = H.runInputT H.defaultSettings $ fromReaderT runApp

Since: 0.8.4.0

data InputTEnv (m :: Type -> Type) Source #

The abstract environment used by InputT, for ReaderT usage.

Since: 0.8.4.0

mapInputTEnv :: (forall x. m x -> n x) -> InputTEnv m -> InputTEnv n Source #

Maps the environment.

Since: 0.8.4.0