I’m trying to create a class that takes a type list and produces a function that creates a tuple with the types in the type list. This seems like it should be doable but I always struggle with this type of thing.
type Tuple :: [Type] -> Constraint
class Tuple ts where tuple :: ????
I have come up with the non-working implementation of
type Tuple :: [Type] -> Constraint
class Tuple ts where tuple :: TupleConstructor ts
type TupleConstructor :: [Type] -> Type
type TupleConstructor ts = TupleConstructor' ts (TupleType ts)
type TupleConstructor' :: [Type] -> Type -> Type
type family TupleConstructor' ts result where
TupleConstructor' '[a,b] result = a -> b -> result
TupleConstructor' (a ': ts) result = a -> TupleConstructor ts result
type TupleType :: [Type] -> Type
type family TupleType ts where
TupleType '[a,b] = (a,b)
TupleType (a ': ts) = (a, TupleType ts)
but the class is all messed up. Is there a way to do this?