Skip to content

Commit 6f3d06f

Browse files
committed
[ refactor ] Get rid of DerivingClosure interface, nail in down
1 parent 0a2feb4 commit 6f3d06f

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/Deriving/DepTyCheck/Gen/ForAllNeededTypes/Impl.idr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ lookupLengthChecked intSig m = lookup intSig m >>= \(extSig, name) => (name,) <$
4545
Yes prf => Just $ Element extSig prf
4646
No _ => Nothing
4747

48-
DeriveBodyForType => ClosuringContext m => Elaboration m => DerivationClosure m where
48+
Deriving.DepTyCheck.Gen.ForAllNeededTypes.Interface.DerivationClosure m = (DeriveBodyForType, Monad m, Elaboration m, ClosuringContext m)
4949

50-
needWeightFun ty = when (not !(gets $ contains ty.name)) $ do
50+
Deriving.DepTyCheck.Gen.ForAllNeededTypes.Interface.needWeightFun ty = when (not !(gets $ contains ty.name)) $ do
5151
modify {stateType=SortedSet Name} $ insert ty.name
5252
_ : (NamesInfoInTypes, ConsRecs) <- get
5353
whenJust (deriveWeightingFun ty) $ tell . mapHom singleton
5454

55-
callGen sig fuel values = do
55+
Deriving.DepTyCheck.Gen.ForAllNeededTypes.Interface.callGen sig fuel values = do
5656

5757
-- look for external gens, and call it if exists
5858
let Nothing = lookupLengthChecked sig !ask

src/Deriving/DepTyCheck/Gen/ForAllNeededTypes/Interface.idr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import public Deriving.DepTyCheck.Gen.Signature
1010
--------------------------------------------------
1111

1212
public export
13-
interface Monad m => DerivationClosure m where
14-
needWeightFun : TypeInfo -> m ()
15-
callGen : (sig : GenSignature) -> (fuel : TTImp) -> Vect sig.givenParams.size TTImp -> m (TTImp, Maybe (gend ** Vect gend $ Fin gend))
16-
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
-- this is a permutation of generated arguments --/
18-
-- actually, `gend` can be calculated from `sig`, but we simplify things here
13+
DerivationClosure : (Type -> Type) -> Type
1914

2015
export
21-
DerivationClosure m => MonadTrans t => Monad (t m) => DerivationClosure (t m) where
22-
needWeightFun = lift . needWeightFun
23-
callGen sig fuel params = lift $ callGen sig fuel params
16+
needWeightFun : DerivationClosure m => TypeInfo -> m ()
17+
18+
export
19+
callGen : DerivationClosure m =>
20+
(sig : GenSignature) -> (fuel : TTImp) -> Vect sig.givenParams.size TTImp -> m (TTImp, Maybe (gend ** Vect gend $ Fin gend))
21+
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
-- this is a permutation of generated arguments --/
23+
-- actually, `gend` can be calculated from `sig`, but we simplify things here
2424

2525
-------------------
2626
--- Conventions ---

src/Deriving/DepTyCheck/Gen/ForOneType/Impl.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ DeriveBodyRhsForCon => DeriveBodyForType where
5858
| Nothing => fail "INTERNAL ERROR: unknown type for consRecs: \{show sig.targetType.name}"
5959

6060
-- ask to derive all needed weigthing functions, if any
61-
traverse_ needWeightFun $ mapMaybe (usedWeightFun . snd) consRecs
61+
traverse_ (needWeightFun {m}) $ mapMaybe (usedWeightFun . snd) consRecs
6262

6363
-- decide how to name a fuel argument on the LHS
6464
let fuelArg = "^fuel_arg^" -- I'm using a name containing chars that cannot be present in the code parsed from the Idris frontend

src/Deriving/DepTyCheck/Gen/ForOneTypeConRhs/Impl.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export
287287
let subfuel = if mutRec then fuel else var outmostFuelArg
288288

289289
-- Form an expression to call the subgen
290-
(subgenCall, reordering) <- callGen subsig subfuel $ snd <$> subgivens
290+
(subgenCall, reordering) <- lift $ callGen {m} subsig subfuel $ snd <$> subgivens
291291

292292
-- Form an expression of binding the result of subgen
293293
let genedArg:::subgeneratedArgs = genedArg:::subgeneratedArgs <&> bindVar . flip Vect.index bindNames

0 commit comments

Comments
 (0)