-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple command line argument parsing -- @package getopt-generics @version 0.9 module System.Console.GetOpt.Generics -- | simpleCLI converts an IO operation into a program with a nice -- CLI. main can have arbitrarily many parameters provided all -- parameters have an instance for Option. -- -- Example: -- -- Given a file myProgram.hs: -- --
-- main :: IO () -- main = simpleCLI myMain -- -- myMain :: String -> Int -> Bool -> IO () -- myMain s i b = print (s, i, b) ---- -- you get: -- --
-- $ runhaskell myProgram.hs foo 42 true
-- ("foo",42,True)
-- $ runhaskell myProgram.hs foo 42 bar
-- cannot parse as BOOL: bar
-- $ runhaskell myProgram.hs --help
-- myProgram.hs [OPTIONS] STRING INTEGER BOOL
-- -h --help show help and exit
--
simpleCLI :: (SimpleCLI main, All Option (ArgumentTypes main)) => main -> IO ()
-- | Parses command line arguments (gotten from withArgs) and
-- returns the parsed value. This function should be enough for simple
-- use-cases.
--
-- May throw the following exceptions:
--
-- -- to . from === id :: a -> a -- from . to === id :: Rep a -> Rep a ---- -- You typically don't define instances of this class by hand, but rather -- derive the class instance automatically. -- -- Option 1: Derive via the built-in GHC-generics. For this, you -- need to use the DeriveGeneric extension to first derive an -- instance of the Generic class from module GHC.Generics. -- With this, you can then give an empty instance for Generic, and -- the default definitions will just work. The pattern looks as follows: -- --
-- import qualified GHC.Generics as GHC -- import Generics.SOP -- -- ... -- -- data T = ... deriving (GHC.Generic, ...) -- -- instance Generic T -- empty -- instance HasDatatypeInfo T -- empty, if you want/need metadata ---- -- Option 2: Derive via Template Haskell. For this, you need to -- enable the TemplateHaskell extension. You can then use -- deriveGeneric from module Generics.SOP.TH to have the -- instance generated for you. The pattern looks as follows: -- --
-- import Generics.SOP -- import Generics.SOP.TH -- -- ... -- -- data T = ... -- -- deriveGeneric ''T -- derives HasDatatypeInfo as well ---- -- Tradeoffs: Whether to use Option 1 or 2 is mainly a matter of -- personal taste. The version based on Template Haskell probably has -- less run-time overhead. -- -- Non-standard instances: It is possible to give Generic -- instances manually that deviate from the standard scheme, as long as -- at least -- --
-- to . from === id :: a -> a ---- -- still holds. class (SingI [[*]] (Code a), All [*] (SingI [*]) (Code a)) => Generic a where type family Code a :: [[*]] -- | A class of datatypes that have associated metadata. -- -- It is possible to use the sum-of-products approach to generic -- programming without metadata. If you need metadata in a function, an -- additional constraint on this class is in order. -- -- You typically don't define instances of this class by hand, but rather -- derive the class instance automatically. See the documentation of -- Generic for the options. class HasDatatypeInfo a -- | The code of a datatype. -- -- This is a list of lists of its components. The outer list contains one -- element per constructor. The inner list contains one element per -- constructor argument (field). -- -- Example: The datatype -- --
-- data Tree = Leaf Int | Node Tree Tree ---- -- is supposed to have the following code: -- --
-- type instance Code (Tree a) = -- '[ '[ Int ] -- , '[ Tree, Tree ] -- ] ---- | Require a constraint for every element of a list of lists. -- -- If you have a datatype that is indexed over a type-level list of -- lists, then you can use All2 to indicate that all elements of -- the innert lists must satisfy a given constraint. -- -- Example: The constraint -- --
-- All2 Eq '[ '[ Int ], '[ Bool, Char ] ] ---- -- is equivalent to the constraint -- --
-- (Eq Int, Eq Bool, Eq Char) ---- -- Example: A type signature such as -- --
-- f :: All2 Eq xss => SOP I xs -> ... ---- -- means that f can assume that all elements of the sum of -- product satisfy Eq. -- | Implicit singleton. -- -- A singleton can be used to reveal the structure of a type argument -- that the function is quantified over. -- -- The class SingI should have instances that match the family -- instances for Sing. class SingI (a :: k) -- | A concrete, poly-kinded proxy type data Proxy (t :: k) :: k -> * Proxy :: Proxy