-- | Helper.
inlineS' :: (Ord c, Ord tc, Ord tv)
  => TcEnv v c tc tv -> Set tc
  -> tc -> [Type tc tv] -> Inliner tc [(Weight, DataPat c tc tv)]
inlineS' env stack tc targs = do
  let (vs, cs) = tyConEnv env Map.! tc
      sub = mkSub vs targs
  alts' <- forM cs $ \c -> do
    let Forall _ ty = conEnv env Map.! c
        cargsTy = fst (unFun $ subst sub ty)
    cargs' <- forM cargsTy $ inlineS env stack
    return $ combine (DPCon c) <$> sequence cargs'
  return . scaleWeights (1 % length cs) $ concat alts'

-- * Inlining for base cases

-- Base cases are also inlined, but within the same state instance,
-- to preserve "consistency" of base cases.

-- | Types are ranked depending on how well founded their base cases are.
inlineS' :: (Ord c, Ord tc, Ord tv)
  => TcEnv v c tc tv -> Set tc
  -> tc -> [Type tc tv] -> Inliner tc [(Weight, DataPat c tc tv)]
inlineS' env stack tc targs = do
  let (vs, cs) = tyConEnv env Map.! tc
      sub = mkSub vs targs
  alts' <- forM cs $ \c -> do
    let Forall _ ty = conEnv env Map.! c
        cargsTy = fst (unFun $ subst sub ty)
    cargs' <- forM cargsTy $ inlineS env stack
    return $ combine (DPCon c) <$> sequence cargs'
  return . scaleWeights (1 % length cs) $ concat alts'

-- * Inlining for base cases

-- Base cases are also inlined, but within the same state instance,
-- to preserve "consistency" of base cases.

-- | Types are ranked depending on how well founded their base cases are.
inlineS' env stack tc targs = do
  let (vs, cs) = tyConEnv env Map.! tc
      sub = mkSub vs targs
  alts' <- forM cs $ \c -> do
    let Forall _ ty = conEnv env Map.! c
        cargsTy = fst (unFun $ subst sub ty)
    cargs' <- forM cargsTy $ inlineS env stack
    return $ combine (DPCon c) <$> sequence cargs'
  return . scaleWeights (1 % length cs) $ concat alts'

-- * Inlining for base cases

-- Base cases are also inlined, but within the same state instance,
-- to preserve "consistency" of base cases.

-- | Types are ranked depending on how well founded their base cases are.