[refactor] Modified to use TH as classy-effects-th now supports dependent effect parameters.

This commit is contained in:
Yamada Ryo 2023-10-03 13:27:46 +09:00
parent d89d6968bc
commit 325b266047
No known key found for this signature in database
GPG Key ID: AAE3C7A542B02DBF
6 changed files with 8 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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,

View File

@ -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,