-- mk_getopt_th ----------------------------------------------------------------

-- | generated getopts-like fn
--
--   (getoptsx :: (NFData a, Show a) => (String -> IO a) -> IO ([a], Getoptsx)
--    getoptsx = (t2apply (checkEx . getoptsx_effect))
--               . (getopts getoptsx_ (ArgSome 1 3) "integer")
--    above)

mk_getopt_th :: Type    -- ^ type signature of generated fn
             -> String  -- ^ name of fn to generate (getoptsx above)
             -> ArgArity                         -- ^ arity of arguments
             -> String                           -- ^ arg type (for help text)
             -> [Dec]

mk_getopt_th sig getoptName arity argtype =
  mkSimpleTypedFun sig (mkName getoptName) [] (infix2E lhs (VarE '(.)) rhs)
    where -- (getopts getoptsx_ (ArgSome 1 3) "integer" above)
          rhs = mAppE [ VarE 'getopts, cfg_name getoptName
                      , liftAA arity, (LitE . StringL) argtype ]
          -- (t2apply (checkEx . getoptsx_effect) above)
          lhs = AppE (VarE 't2apply)
                     (composeE (VarE 'checkEx) (effect_name getoptName))

-- mkGetoptTHTypeSig -----------------------------------------------------------

{- | type signature for generated getopts-like fn, e.g.,

     > (NFData a, Show a) =>
     >  ArgArity -> String -> (String -> IO a) -> IO ([a], Getoptsx)
 -}
mk_getopt_th :: Type    -- ^ type signature of generated fn
             -> String  -- ^ name of fn to generate (getoptsx above)
             -> ArgArity                         -- ^ arity of arguments
             -> String                           -- ^ arg type (for help text)
             -> [Dec]
mk_getopt_th sig getoptName arity argtype =
  mkSimpleTypedFun sig (mkName getoptName) [] (infix2E lhs (VarE '(.)) rhs)
    where -- (getopts getoptsx_ (ArgSome 1 3) "integer" above)
          rhs = mAppE [ VarE 'getopts, cfg_name getoptName
                      , liftAA arity, (LitE . StringL) argtype ]
          -- (t2apply (checkEx . getoptsx_effect) above)
          lhs = AppE (VarE 't2apply)
                     (composeE (VarE 'checkEx) (effect_name getoptName))

-- mkGetoptTHTypeSig -----------------------------------------------------------

{- | type signature for generated getopts-like fn, e.g.,

     > (NFData a, Show a) =>
     >  ArgArity -> String -> (String -> IO a) -> IO ([a], Getoptsx)
 -}
mk_getopt_th sig getoptName arity argtype =
  mkSimpleTypedFun sig (mkName getoptName) [] (infix2E lhs (VarE '(.)) rhs)
    where -- (getopts getoptsx_ (ArgSome 1 3) "integer" above)
          rhs = mAppE [ VarE 'getopts, cfg_name getoptName
                      , liftAA arity, (LitE . StringL) argtype ]
          -- (t2apply (checkEx . getoptsx_effect) above)
          lhs = AppE (VarE 't2apply)
                     (composeE (VarE 'checkEx) (effect_name getoptName))

-- mkGetoptTHTypeSig -----------------------------------------------------------

{- | type signature for generated getopts-like fn, e.g.,

     > (NFData a, Show a) =>
     >  ArgArity -> String -> (String -> IO a) -> IO ([a], Getoptsx)
 -}