Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use makeSem_ in Minecraft.Effect #1

Open
evanrelf opened this issue Jan 5, 2021 · 0 comments
Open

Use makeSem_ in Minecraft.Effect #1

evanrelf opened this issue Jan 5, 2021 · 0 comments

Comments

@evanrelf
Copy link

evanrelf commented Jan 5, 2021

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant