-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Tools for working with functions of undetermined arity
--   
--   Tools for working with functions of undetermined arity
@package poly-arity
@version 0.1.0

module Data.Function.Poly

-- | Provide a type-level list of <i>types</i> <tt>xs</tt>, and a final
--   result type <tt>r</tt>, construct a chain of arrows <tt>-&gt;</tt> /
--   n-ary function (which is right-associative) of each type in
--   <tt>xs</tt>, ending in <tt>r</tt>.

-- | The inverse of <tt>TypeListToArity</tt>.

-- | Trim an n-ary function / chain of arrows <tt>-&gt;</tt> with a
--   type-level list of types <tt>xs</tt>, where each element of
--   <tt>xs</tt> <b>must</b> unify with each element of the cons-list made
--   with <tt>-&gt;</tt>.
type ArityTypeListIso c l r = (ArityMinusTypeList c l ~ r, c ~ TypeListToArity l r)

-- | Injects a type to the base of the function arity chain.

-- | Inductively constrain a function's initial arity to match a type list;
--   as a read-only style of static arity assurance.

-- | Expect the last parameter in your stack of arity to have a type.

-- | Duplicate of <a>singletons</a> <tt>Head</tt> function for
--   kind-polymorphic type-level lists.
data HList (xs :: [*])
[HNil] :: HList '[]
[HCons] :: (x :: *) -> HList xs -> HList (x : xs)

-- | Lift the <tt>HList</tt>'s internal type-level list of types to a
--   constraint context.
class ExpectArity xs f => ConsumeArity (xs :: [*]) (f :: *) result | xs f -> result

-- | Use a <i>heterogeneously-typed</i> list of values as input to an n-ary
--   function, where types must unify statically.
appN :: ConsumeArity xs f result => f -> HList xs -> result

-- | Shows that an n-ary function <tt>f</tt> <i>precisely</i> ends with
--   <tt>r</tt>.
instance Data.Function.Poly.ConsumeArity '[] r r
instance (Data.Function.Poly.ConsumeArity xs f r, Data.Function.Poly.ExpectArity (x : xs) (x -> f)) => Data.Function.Poly.ConsumeArity (x : xs) (x -> f) r
