From 325b2660470f3548806de3ea88d42ae917606cbc Mon Sep 17 00:00:00 2001 From: Yamada Ryo Date: Tue, 3 Oct 2023 13:27:46 +0900 Subject: [PATCH] [refactor] Modified to use TH as classy-effects-th now supports dependent effect parameters. --- cabal.project | 2 +- heftia-effects/Example/DepParams/Main.hs | 32 +++--------------------- heftia/src/Control/Effect/Freer.hs | 2 +- heftia/src/Control/Effect/Heftia.hs | 2 +- heftia/src/Data/Free/Union.hs | 2 +- heftia/src/Data/Hefty/Union.hs | 2 +- 6 files changed, 8 insertions(+), 34 deletions(-) diff --git a/cabal.project b/cabal.project index 6db2788..89ddf8d 100644 --- a/cabal.project +++ b/cabal.project @@ -5,7 +5,7 @@ packages: source-repository-package type: git location: https://github.com/sayo-hs/classy-effects - tag: 86dda61d2f4d5c66fd754a606775efb55dea0977 + tag: fe8bcc5e5be492a021a464a887dd120f138c2d91 subdir: classy-effects-base subdir: classy-effects-th subdir: classy-effects diff --git a/heftia-effects/Example/DepParams/Main.hs b/heftia-effects/Example/DepParams/Main.hs index ef69699..1268758 100644 --- a/heftia-effects/Example/DepParams/Main.hs +++ b/heftia-effects/Example/DepParams/Main.hs @@ -14,8 +14,6 @@ The original of this example can be found at polysemy. module Main where import Control.Effect.Class ( - EffectDataHandler, - EffectsVia (EffectsVia), Taggable, getTag, sendIns, @@ -24,20 +22,11 @@ import Control.Effect.Class ( type (@#), type (~>), ) -import Control.Effect.Class.Machinery.DepParam ( - DepParams, - DepParamsFor, - DepParamsOf, - EffectClassIdentifierOf, - InsClassOf, - SendInsDep, - type (#-), - ) +import Control.Effect.Class.Machinery.DepParams (type (#-)) +import Control.Effect.Class.Machinery.TH (makeEffectF) import Control.Effect.Freer (Fre, interpose, interpret, runFreerEffects, untag, type (<|-)) -import Data.Effect.Class.TH (makeInstruction) import Data.Free.Union (FindFirstDepParams, InsClassIn) import Data.Function ((&)) -import Data.Kind (Type) import Data.String (IsString) import Data.Tuple (Solo (Solo)) @@ -45,22 +34,7 @@ class Teletype s f | f -> s where readTTY :: f s writeTTY :: s -> f () -data I'Teletype -type instance DepParams I'Teletype = Solo Type - -makeInstruction ''Teletype - -type instance InsClassOf I'Teletype ('Solo s) = TeletypeI s - -type instance EffectClassIdentifierOf (TeletypeI s) = I'Teletype -type instance DepParamsOf (TeletypeI s) = 'Solo s - -instance - (SendInsDep I'Teletype f, 'Solo s ~ DepParamsFor I'Teletype f) => - Teletype s (EffectsVia EffectDataHandler f) - where - readTTY = EffectsVia . sendIns $ ReadTTY - writeTTY = EffectsVia . sendIns . WriteTTY +makeEffectF ''Teletype teletypeToIO :: (IO <: Fre es m, Monad m) => Fre (TeletypeI String ': es) m ~> Fre es m teletypeToIO = interpret \case diff --git a/heftia/src/Control/Effect/Freer.hs b/heftia/src/Control/Effect/Freer.hs index 79a9ef5..db39eb5 100644 --- a/heftia/src/Control/Effect/Freer.hs +++ b/heftia/src/Control/Effect/Freer.hs @@ -35,7 +35,7 @@ import Control.Effect.Class ( type (~>), ) import Control.Effect.Class.Fail (FailI (Fail)) -import Control.Effect.Class.Machinery.DepParam (QueryDepParamsFor) +import Control.Effect.Class.Machinery.DepParams (QueryDepParamsFor) import Control.Freer.Trans ( TransFreer, hoistFreer, diff --git a/heftia/src/Control/Effect/Heftia.hs b/heftia/src/Control/Effect/Heftia.hs index 2758d41..8cbbc27 100644 --- a/heftia/src/Control/Effect/Heftia.hs +++ b/heftia/src/Control/Effect/Heftia.hs @@ -38,7 +38,7 @@ import Control.Effect.Class ( ) import Control.Effect.Class.Fail (FailI (Fail)) import Control.Effect.Class.Fix (FixS (Mfix)) -import Control.Effect.Class.Machinery.DepParam (QueryDepParamsFor) +import Control.Effect.Class.Machinery.DepParams (QueryDepParamsFor) import Control.Effect.Class.Machinery.HFunctor (HFunctor, hfmap) import Control.Effect.Freer (FreerEffects, freerEffects, interpose, unFreerEffects) import Control.Freer.Trans (TransFreer, interpretFT, liftInsT, liftLowerFT) diff --git a/heftia/src/Data/Free/Union.hs b/heftia/src/Data/Free/Union.hs index 74b0581..ba85915 100644 --- a/heftia/src/Data/Free/Union.hs +++ b/heftia/src/Data/Free/Union.hs @@ -16,7 +16,7 @@ implementation. module Data.Free.Union where import Control.Effect.Class (Instruction, type (~>)) -import Control.Effect.Class.Machinery.DepParam ( +import Control.Effect.Class.Machinery.DepParams ( DepParams, DepParamsOf, EffectClassIdentifier, diff --git a/heftia/src/Data/Hefty/Union.hs b/heftia/src/Data/Hefty/Union.hs index d49dea1..9711967 100644 --- a/heftia/src/Data/Hefty/Union.hs +++ b/heftia/src/Data/Hefty/Union.hs @@ -17,7 +17,7 @@ implementation. module Data.Hefty.Union where import Control.Effect.Class (Signature, type (~>)) -import Control.Effect.Class.Machinery.DepParam ( +import Control.Effect.Class.Machinery.DepParams ( DepParams, DepParamsOfH, EffectClassIdentifier,