{-# LANGUAGE UndecidableInstances #-} module CLI.Orchestrator.Utils ( Singleton , rangeNP ) where import Data.Kind (Constraint) import Generics.SOP (All, K (K), NP, Top) import Generics.SOP.NP (ana_NP) type Singleton :: [k] -> Constraint class Singleton a where instance Singleton '[x] where -- | [0..n] but for NP and the `n` is derived from `xs`. rangeNP :: All Top xs => NP (K Int) xs rangeNP = ana_NP f (K 0) where f :: K Int (y : ys) -> (K Int y, K Int ys) f (K i) = (K i, K $ i + 1)