-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A modern command-line parser for Haskell. -- -- A modern command-line parser for Haskell. @package lambda-options @version 0.2.0.0 module Text.LambdaOptions -- | A monad transformer for parsing options. data Options m a -- | An option keyword, such as "--help" -- -- NB: In the future, this will become a proper data type that contains a -- list of aliases and help descriptions. type Keyword = String -- | The callback to be called for a successfully parsed option. -- -- This function (or value) can have any arity and ultimately returns a -- value with type Monad m => m () -- -- Each of the callback's arguments must have a type t which -- implements Parseable and Typeable. -- -- Think of this as the following constraint synonym: -- --
--   type OptionCallback m f = (Monad m, f ~ (Parseable t*, Typeable t*) => t0 -> t1 -> ... -> tN -> m ())
--   
-- -- Example callbacks: -- --
--   putStrLn "Option parsed!" :: IO ()
--   put :: String -> State String ()
--   \n -> liftIO (print n) :: (MonadIO m) => Int -> m ()
--   \name year ratio -> lift (print (name, year, ratio)) :: (MonadTrans m) => String -> Int -> Float -> m IO ()
--   
type OptionCallback m f = (Monad m, GetOpaqueParsers f, WrapCallback m f) -- | Adds the supplied option to the Options m () context. -- -- If the keyword is matched and the types of the callback's parameters -- can successfully be parsed, the callback is called with the parsed -- arguments. addOption :: OptionCallback m f => Keyword -> f -> Options m () -- | Contains information about what went wrong during an unsuccessful -- options parse. data OptionsError -- | Contains (error-message) (begin-args-index) -- (end-args-index) ParseFailed :: String -> Int -> Int -> OptionsError -- | Tries to parse the supplied options against input arguments. If -- successful, parsed option callbacks are executed. Otherwise -- none of the callbacks are executed. -- -- Example: -- --
--   options :: Options IO ()
--   options = do
--       addOption "--help" $ do
--           putStrLn "--user NAME [AGE]"
--       addOption "--user" $ name -> do
--           putStrLn $ Name: ++ name
--       addOption "--user" $ name age -> do
--           putStrLn $ Name: ++ name ++ " Age:" ++ show (age :: Int)
--   
--   main :: IO ()
--   main = do
--       args <- getArgs
--       mError <- runOptions options args
--       case mError of
--           Just (ParseFailed _ _ _) -> exitFailure
--           Nothing -> exitSuccess
--   
runOptions :: Monad m => Options m a -> [String] -> m (Maybe OptionsError) -- | Class describing parseable values. Much like the Read class. class Parseable a parse :: Parseable a => [String] -> (Maybe a, Int) -- | A simple wrapper over [a]. Used to avoid overlapping -- instances for Parseable [a] and Parseable String newtype List a List :: [a] -> List a instance Show a => Show (List a) instance Read a => Read (List a) instance Eq a => Eq (List a) instance Ord a => Ord (List a) instance (Monad m, Functor m) => Applicative (Options m) instance Functor m => Functor (Options m) instance Monad m => Monad (Options m) instance Monad m => MonadState (OptionsState m) (Options m) instance MonadIO m => MonadIO (Options m) instance Show OptionsError instance MonadTrans Options instance (Typeable a, WrapCallback m b) => WrapCallback m (a -> b) instance WrapCallback m (m ()) instance Monad m => GetOpaqueParsers (m ()) instance (Parseable a, Typeable a, GetOpaqueParsers b) => GetOpaqueParsers (a -> b) instance Parseable a => Parseable (List a) instance Parseable a => Parseable (Maybe a) instance Parseable Float instance Parseable String instance Parseable Int