Creating a large tuple from smaller tuples via a monad or applicative
(Note, this requires a more sophisticated type theory such as System Fω to encode)
This idea is captured by the concept of an indexed monad (and in turn indexed applicative/functor).
Using Haskell as lingua franca, we talk about a typeclass:
class IxMonad (m :: n -&gt; n -&gt; * -&gt; *) where                    
  ireturn :: a -&gt; m i i a
  ibind :: m i j a -&gt; (a -&gt; m j k b) -&gt; m i k b
  {- alternatively, if it's an IxFunctor, the categorical version:
  ireturn :: a -&gt; m i i a
  ijoin :: m i j (m j k a) -&gt; m i k a
  -}

An action m i j a makes a connection &quot;from&quot; an index i &quot;to&quot; an index j, and wraps some type a. Actions can be composed only if the respective indices &quot;line up&quot;. Sort of like how horizontal oidification turns a monoid into a category: morphisms can be composed only if their endpoint objects &quot;line up&quot;.
Analogous definitions of an indexed functor and an indexed applicative can be made:
class IxFunctor (m :: n -&gt; n -&gt; * -&gt; *) where
  ifmap :: (a -&gt; b) -&gt; m i j a -&gt; m i j b

class IxApplicative (m :: n -&gt; n -&gt; * -&gt; *) where
  ipure :: a -&gt; m i i a
  iap :: m i j (a -&gt; b) -&gt; m j k a -&gt; m i k b
  {- alternatively, if it's an IxFunctor, the categorical version:
  iunit :: () -&gt; m i i ()
  iprod :: (m i j a, m j k b) -&gt; m i k (a, b)
  -}

Say we wanted to &quot;output&quot; entries of some type, while keeping a type-theoretic witness of how many entries there are, we could define an indexed writer monad.
Here's definitions of natural numbers used to track length, and a length-indexed &quot;log&quot; datatype:
data N = Z | S N

data Vec (n :: N) (a :: *) where
  Nil :: Vec 'Z a
  Cons :: a -&gt; Vec n a -&gt; Vec ('S n) a

In an indexed monad, the usual intuition is that the indices i/j describe the &quot;state&quot; of the system: an action brings the system from &quot;state i&quot; to &quot;state j&quot;. Here we'll be using the index to track how many entries we've written to the &quot;log&quot;, and for completely technical reasons (to do with making the typechecker happy in an easy way), the left index will be the output log length, and the right index will be the input log length:
type family Add (n :: N) (m :: N) :: N where
  Add 'Z m = m
  Add ('S n) m = 'S (Add n m)

data IxWriter w i j a where
  IxWriter :: Vec k w -&gt; a -&gt; IxWriter w (Add k i) i a

instance IxMonad (IxWriter w) where
  ireturn x = IxWriter Nil x
  ibind (IxWriter xs x) f = case f x of
    IxWriter fs y -&gt; iwappend xs fs y
    where
      iwcons :: w -&gt; IxWriter w i j a -&gt; IxWriter w ('S i) j a
      iwcons p (IxWriter qs z) = IxWriter (Cons p qs) z

      iwappend :: Vec k1 w -&gt; Vec k2 w -&gt; a -&gt; IxWriter w (Add k1 (Add k2 i)) i a
      iwappend (Cons p ps) qs z = iwcons p $ iwappend ps qs z
      iwappend Nil qs z = IxWriter qs z

Then we can define the &quot;logging&quot; action, and an interpreter for our effect:
itell :: Vec k w -&gt; IxWriter w (Add k i) i ()
itell ps = IxWriter ps ()

runIxWriter :: IxWriter w i 'Z a -&gt; (Vec i w, a)
runIxWriter (IxWriter Nil x) = (Nil, x)
runIxWriter (IxWriter (Cons p ps) x) = case runIxWriter (IxWriter ps x) of
  (qs, r) -&gt; (Cons p qs, r)

With this we can keep track of exactly how many entries we've logged:
case runIxWriter $
  itell (Cons 1 Nil) `ibind` \_ -&gt; itell (Cons 2 Nil) `ibind` \_ -&gt; itell (Cons 3 Nil)
of (Cons a (Cons b (Cons c Nil)), x) -&gt; (a, b, c, x)
{- pattern match is valid and complete because we
   statically know it's a Vec ('S ('S ('S 'Z))) Integer -}

Here we used the graded monoid of finite sequences (and thus all our logs are of the same type). In theory we could have used any monoid graded by any other monoid, (for example the monoid of heterogeneous lists, graded by the monoid of lists of types -- if we wanted to be able to talk about heterogeneous tuples)