on-demand-minecraft icon indicating copy to clipboard operation
on-demand-minecraft copied to clipboard

Use `makeSem_` in `Minecraft.Effect`

Open evanrelf opened this issue 3 years ago • 0 comments

Hi there! 🙂 This is a cool project. I'd love to try this out someday for my own Minecraft server.

I noticed you aren't using makeSem in Minecraft.Effect because you want to rearrange the type variables for more convenient TypeApplications. I would recommend using makeSem_, so that you only need to provide the type signatures, and not the function bodies.

I believe something like this would work, however I'm unable to enter your Nix shell to verify due to some issue with Nix and the linker on macOS Big Sur:

diff --git a/lib/Minecraft/Effect.hs b/lib/Minecraft/Effect.hs
index 7b925ed..b0d4df7 100644
--- a/lib/Minecraft/Effect.hs
+++ b/lib/Minecraft/Effect.hs
@@ -4,6 +4,7 @@
 {-# LANGUAGE LambdaCase          #-}
 {-# LANGUAGE OverloadedStrings   #-}
 {-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TemplateHaskell     #-}
 {-# LANGUAGE TypeApplications    #-}
 {-# LANGUAGE TypeFamilies        #-}
 {-# LANGUAGE TypeOperators       #-}
@@ -41,35 +42,27 @@ data Minecraft (side :: Side) (m :: * -> *) a where
     => Minecraft side m (Maybe packet)
   ReceivePacket ::
     (packet ~ Consumes side state, Store packet, Show packet)
-    => Minecraft side m (Consumes side state)
+    => Minecraft side m packet
   SendPacket ::
     (packet ~ Produces side state, Store packet, Show packet)
     => packet -> Minecraft side m ()
 
 
--- These are the same as with
---   makeSem ''Minecraft
--- But with the state argument moved to the front for more convenience
+makeSem_ ''Minecraft
 
-type instance Polysemy.Internal.CustomErrors.DefiningModule Minecraft = "Minecraft.Packet"
+-- Moving the state argument to the front for more convenience
 
-{-# INLINABLE maybeReceivePacket #-}
 maybeReceivePacket :: forall state side r packet
   . (MemberWithError (Minecraft side) r, packet ~ Consumes side state, Store packet, Show packet)
   => Sem r (Maybe packet)
-maybeReceivePacket = Polysemy.Internal.send MaybeReceivePacket
 
-{-# INLINABLE receivePacket #-}
 receivePacket :: forall state side r packet
   . (MemberWithError (Minecraft side) r, packet ~ Consumes side state, Store packet, Show packet)
   => Sem r (Consumes side state)
-receivePacket = Polysemy.Internal.send ReceivePacket
 
-{-# INLINABLE sendPacket #-}
 sendPacket :: forall state side r packet
   . (MemberWithError (Minecraft side) r, packet ~ Produces side state, Store packet, Show packet)
   => packet -> Sem r ()
-sendPacket = Polysemy.Internal.send . SendPacket
 
 
 runMinecraft :: forall side r a . Members '[Trace, Async, Final IO, Error String] r => Socket -> Sem (Minecraft side ': r) a -> Sem r a

evanrelf avatar Jan 05 '21 05:01 evanrelf