sortQuantVars :: [Var] -> [Var]
-- Sort the variables (KindVars, TypeVars, and Ids)
-- into order: Kind, then Type, then Id
sortQuantVars = sortBy (comparing withCategory)
  where
    withCategory v = (category v, v)
    category :: Var -> Int
    category v
     | isKindVar v = 1
     | isTyVar   v = 2
     | otherwise   = 3

-- | Bind a binding group over an expression, using a @let@ or @case@ as
-- appropriate (see "CoreSyn#let_app_invariant")
sortQuantVars :: [Var] -> [Var]
sortQuantVars = sortBy (comparing withCategory)
  where
    withCategory v = (category v, v)
    category :: Var -> Int
    category v
     | isKindVar v = 1
     | isTyVar   v = 2
     | otherwise   = 3

-- | Bind a binding group over an expression, using a @let@ or @case@ as
-- appropriate (see "CoreSyn#let_app_invariant")
sortQuantVars = sortBy (comparing withCategory)
  where
    withCategory v = (category v, v)
    category :: Var -> Int
    category v
     | isKindVar v = 1
     | isTyVar   v = 2
     | otherwise   = 3

-- | Bind a binding group over an expression, using a @let@ or @case@ as
-- appropriate (see "CoreSyn#let_app_invariant")