From f9173c06b76fbbb70ff14b1a51dd1e0115a0f917 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 31 May 2017 15:22:32 -0400 Subject: [PATCH] Define a type family to constrain every element of a list of types. --- src/Data/Record.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Data/Record.hs b/src/Data/Record.hs index 57662d633..891275957 100644 --- a/src/Data/Record.hs +++ b/src/Data/Record.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, GADTs, KindSignatures, MultiParamTypeClasses, TypeOperators #-} +{-# LANGUAGE ConstraintKinds, DataKinds, GADTs, KindSignatures, MultiParamTypeClasses, TypeFamilies, TypeOperators #-} module Data.Record where import Data.Functor.Listable @@ -30,6 +30,10 @@ class HasField (fields :: [*]) (field :: *) where getField :: Record fields -> field setField :: Record fields -> field -> Record fields +type family ConstrainAll (toConstraint :: * -> Constraint) (fs :: [*]) :: Constraint where + ConstrainAll toConstraint (f ': fs) = (toConstraint f, ConstrainAll toConstraint fs) + ConstrainAll _ '[] = () + -- Instances