@@ -13,7 +13,7 @@ import qualified Data.Sequence as S
1313import Data.Diverse.Many.Internal (Many (.. ))
1414import Unsafe.Coerce
1515import Numbers
16- -- import GHC.TypeLits as Lits
16+ import GHC.TypeLits as Lits
1717
1818pureRecipe :: Applicative effect => target -> Recipe effect target '[]
1919pureRecipe target = Recipe $ \ _ -> pure target
@@ -120,13 +120,28 @@ instance forall effect target book state.
120120 (s2r, deps) :: (Many state , Many (RecipeDeps effect target book )) <- s2
121121 (res s2r deps) :: effect (Many state , target )
122122
123- finish :: forall target (effect :: * -> * ) (book :: [* ]) (store :: [* ]).
123+ type family Contains (target :: * ) (store :: [* ]) :: Bool where
124+ Contains target (target ': t ) = True
125+ Contains target (h ': t ) = Contains target t
126+ Contains target '[] = False
127+
128+ type family EverythingIsAppliedTypeError (bool :: Bool ) (s :: Type ) (b :: [Type ]) :: Constraint where
129+ EverythingIsAppliedTypeError True s b = ()
130+ EverythingIsAppliedTypeError False s b = TypeError ('Text " The type " ':<>: ShowType s ':<>: 'Text " is not overriding anything in " ':<>: ShowType b )
131+
132+ type family EverythingIsApplied (effect :: * -> * ) target (book :: [* ]) (store :: [* ]) :: Constraint where
133+ EverythingIsApplied effect target ((Recipe effect head _ ) ': tBook ) store = (EverythingIsAppliedTypeError (Contains head store ) head store , EverythingIsApplied effect target tBook store )
134+ EverythingIsApplied effect target (head ': tBook ) store = TypeError ('Text " The type " ':<>: ShowType head ':<>: 'Text " is not a Recipe" )
135+ EverythingIsApplied effect target '[] store = ()
136+
137+ finish :: forall (effect :: * -> * ) target (book :: [* ]) (store :: [* ]).
124138 ( store ~ (LiftMaybe (Nub (RecipeDepsRec effect target book (RecipeDeps effect target book ))))
125139 , ToS (ListLen (EmptyStore effect target book ))
126140 , HasRecipe effect target book
127141 , Monad effect
128142 , (SubSelect effect book (RecipeDeps effect target book ) store )
129143 , (UniqueMember (Maybe target ) store )
144+ , EverythingIsApplied effect target book (Nub (RecipeDepsRec effect target book (RecipeDeps effect target book )))
130145 ) =>
131146 Many book -> effect target
132147finish book = do
@@ -136,8 +151,6 @@ finish book = do
136151 (_, target) <- cook book store (Proxy @ target )
137152 pure target
138153
139- -- test
140-
141154class DefaultRecipe (effect :: * -> * ) target where
142155 type DefaultRecipeDeps effect target :: [* ]
143156 def :: Recipe effect target (DefaultRecipeDeps effect target )
0 commit comments