Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use polysemy-plugin in polysemy #240

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
- async >= 2.2 && < 3
- type-errors >= 0.2.0.0
- type-errors-pretty >= 0.0.0.0 && < 0.1
- polysemy-plugin >= 0.2.3.0

default-extensions:
- DataKinds
Expand Down
2 changes: 1 addition & 1 deletion polysemy-plugin/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ dependencies:
- base >= 4.9 && < 5
- ghc >= 8.4.4 && < 9
- ghc-tcplugins-extra >= 0.3 && < 0.4
- polysemy >= 0.6
- syb >= 0.7 && < 0.8
- transformers >= 0.5.2.0 && < 0.6
- containers >= 0.5 && < 0.7


library:
source-dirs: src

Expand Down
3 changes: 1 addition & 2 deletions polysemy-plugin/polysemy-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 01634ce3c7ac101e60c1a02f8ccad7ec499c02a04b66e5d9dd5993f314318097
-- hash: a62973f46a4e7442a95affe8431d2ab9e49ccc84c71947c6c52cdb5f2d7b59d1

name: polysemy-plugin
version: 0.2.3.0
Expand Down Expand Up @@ -45,7 +45,6 @@ library
, containers >=0.5 && <0.7
, ghc >=8.4.4 && <9
, ghc-tcplugins-extra >=0.3 && <0.4
, polysemy >=0.6
, syb >=0.7 && <0.8
, transformers >=0.5.2.0 && <0.6
default-language: Haskell2010
Expand Down
5 changes: 4 additions & 1 deletion polysemy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 7ce7e4fdc1a3ebff15b38a550ed247a4ad04bb4c383ad4440212926b3eeea93c
-- hash: 8b1a7a539b7611166cce4fb786896e4e459c6c1c2e9016634851419312ddb15d

name: polysemy
version: 1.2.1.0
Expand Down Expand Up @@ -84,6 +84,7 @@ library
, containers >=0.5 && <0.7
, first-class-families >=0.5.0.0 && <0.7
, mtl >=2.2.2 && <3
, polysemy-plugin >=0.2.3.0
, stm >=2 && <3
, syb >=0.7 && <0.8
, template-haskell >=2.12.0.0 && <3
Expand Down Expand Up @@ -148,6 +149,7 @@ test-suite polysemy-test
, inspection-testing >=0.4.2 && <0.5
, mtl >=2.2.2 && <3
, polysemy
, polysemy-plugin >=0.2.3.0
, stm >=2 && <3
, syb >=0.7 && <0.8
, template-haskell >=2.12.0.0 && <3
Expand Down Expand Up @@ -182,6 +184,7 @@ benchmark polysemy-bench
, freer-simple
, mtl
, polysemy
, polysemy-plugin >=0.2.3.0
, stm >=2 && <3
, syb >=0.7 && <0.8
, template-haskell >=2.12.0.0 && <3
Expand Down
7 changes: 4 additions & 3 deletions src/Polysemy/IO.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

module Polysemy.IO
( -- * Interpretations
embedToMonadIO
Expand Down Expand Up @@ -35,13 +37,12 @@ import Polysemy.Internal.Union
-- @
--
embedToMonadIO
:: forall m r a
. ( MonadIO m
:: ( MonadIO m
, Member (Embed m) r
)
=> Sem (Embed IO ': r) a
-> Sem r a
embedToMonadIO = runEmbedded $ liftIO @m
embedToMonadIO = runEmbedded liftIO
{-# INLINE embedToMonadIO #-}


Expand Down
9 changes: 5 additions & 4 deletions src/Polysemy/Internal/Strategy.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_HADDOCK not-home #-}
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

module Polysemy.Internal.Strategy where

Expand Down Expand Up @@ -60,8 +61,8 @@ runStrategy sem = \s wv ins -> run $ interpret
-- See also 'Polysemy.getInspectorT'
--
-- @since 1.2.0.0
getInspectorS :: forall m f n. Sem (WithStrategy m f n) (Inspector f)
getInspectorS = send (GetInspector @m @f @n)
getInspectorS :: Sem (WithStrategy m f n) (Inspector f)
getInspectorS = send GetInspector
{-# INLINE getInspectorS #-}


Expand All @@ -73,8 +74,8 @@ getInspectorS = send (GetInspector @m @f @n)
-- directly.
--
-- @since 1.2.0.0
getInitialStateS :: forall m f n. Sem (WithStrategy m f n) (f ())
getInitialStateS = send (GetInitialState @m @f @n)
getInitialStateS :: Sem (WithStrategy m f n) (f ())
getInitialStateS = send GetInitialState
{-# INLINE getInitialStateS #-}


Expand Down
9 changes: 5 additions & 4 deletions src/Polysemy/Internal/Tactics.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}
{-# OPTIONS_HADDOCK not-home #-}

module Polysemy.Internal.Tactics
Expand Down Expand Up @@ -86,8 +87,8 @@ data Tactics f n r m a where
-- | Get the stateful environment of the world at the moment the effect @e@ is
-- to be run. Prefer 'pureT', 'runT' or 'bindT' instead of using this function
-- directly.
getInitialStateT :: forall f m r e. Sem (WithTactics e f m r) (f ())
getInitialStateT = send @(Tactics _ m (e ': r)) GetInitialState
getInitialStateT :: Sem (WithTactics e f m r) (f ())
getInitialStateT = send GetInitialState


------------------------------------------------------------------------------
Expand All @@ -112,8 +113,8 @@ getInitialStateT = send @(Tactics _ m (e ': r)) GetInitialState
-- @
--
-- We
getInspectorT :: forall e f m r. Sem (WithTactics e f m r) (Inspector f)
getInspectorT = send @(Tactics _ m (e ': r)) GetInspector
getInspectorT :: Sem (WithTactics e f m r) (Inspector f)
getInspectorT = send GetInspector


------------------------------------------------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions src/Polysemy/Output.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE BangPatterns, TemplateHaskell #-}

{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

module Polysemy.Output
( -- * Effect
Output (..)
Expand Down Expand Up @@ -201,15 +203,14 @@ ignoreOutput = interpret $ \case
--
-- @since 1.0.0.0
runOutputBatched
:: forall o r a
. Member (Output [o]) r
:: Member (Output [o]) r
=> Int
-> Sem (Output o ': r) a
-> Sem r a
runOutputBatched 0 m = ignoreOutput m
runOutputBatched size m = do
((c, res), a) <-
runState (0 :: Int, [] :: [o]) $ reinterpret (\case
runState (0 :: Int, []) $ reinterpret (\case
Output o -> do
(count, acc) <- get
let newCount = 1 + count
Expand All @@ -218,9 +219,9 @@ runOutputBatched size m = do
then put (newCount, newAcc)
else do
output (reverse newAcc)
put (0 :: Int, [] :: [o])
put (0, [])
) m
when (c > 0) $ output @[o] (reverse res)
when (c > 0) $ output $ reverse res
pure a

------------------------------------------------------------------------------
Expand Down