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 all 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
3 changes: 3 additions & 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 Expand Up @@ -104,13 +105,15 @@ tests:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -fplugin=Polysemy.Plugin
build-tools:
- hspec-discover >= 2.0
dependencies:
- polysemy
- inspection-testing >= 0.4.2 && < 0.5
- hspec >= 2.6.0 && < 3
- doctest >= 0.16.0.1 && < 0.17
- should-not-typecheck >= 2.1.0 && < 3

benchmarks:
polysemy-bench:
Expand Down
38 changes: 19 additions & 19 deletions polysemy-plugin/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ 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

tests:
polysemy-plugin-test:
main: Main.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -fplugin=Polysemy.Plugin
build-tools:
- hspec-discover
dependencies:
- polysemy >= 1.2.0.0
- polysemy-plugin
- hspec >= 2.6.0 && < 3
- should-not-typecheck >= 2.1.0 && < 3
- inspection-testing >= 0.4.2 && < 0.5
- doctest >= 0.16.0.1 && < 0.17
# tests:
# polysemy-plugin-test:
# main: Main.hs
# source-dirs: test
# ghc-options:
# - -threaded
# - -rtsopts
# - -with-rtsopts=-N
# - -fplugin=Polysemy.Plugin
# build-tools:
# - hspec-discover
# dependencies:
# - polysemy >= 1.2.0.0
# - polysemy-plugin
# - hspec >= 2.6.0 && < 3
# - should-not-typecheck >= 2.1.0 && < 3
# - inspection-testing >= 0.4.2 && < 0.5
# - doctest >= 0.16.0.1 && < 0.17

default-extensions:
- DataKinds
Expand Down
37 changes: 1 addition & 36 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: 40bcdc39ae4c51f9579589c0fbb38bb5773c918d6f5a8b9dcccabd7b9b136230

name: polysemy-plugin
version: 0.2.3.0
Expand Down Expand Up @@ -45,41 +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

test-suite polysemy-plugin-test
type: exitcode-stdio-1.0
main-is: Main.hs
other-modules:
BadSpec
DoctestSpec
ExampleSpec
LegitimateTypeErrorSpec
MultipleVarsSpec
PluginSpec
TypeErrors
VDQSpec
Paths_polysemy_plugin
hs-source-dirs:
test
default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax
ghc-options: -threaded -rtsopts -with-rtsopts=-N -fplugin=Polysemy.Plugin
build-tool-depends:
hspec-discover:hspec-discover
build-depends:
base >=4.9 && <5
, containers >=0.5 && <0.7
, doctest >=0.16.0.1 && <0.17
, ghc >=8.4.4 && <9
, ghc-tcplugins-extra >=0.3 && <0.4
, hspec >=2.6.0 && <3
, inspection-testing >=0.4.2 && <0.5
, polysemy >=1.2.0.0
, polysemy-plugin
, should-not-typecheck >=2.1.0 && <3
, syb >=0.7 && <0.8
, transformers >=0.5.2.0 && <0.6
default-language: Haskell2010
32 changes: 0 additions & 32 deletions polysemy-plugin/test/DoctestSpec.hs

This file was deleted.

1 change: 0 additions & 1 deletion polysemy-plugin/test/Main.hs

This file was deleted.

16 changes: 14 additions & 2 deletions 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: f721d7330405d7fbf95c1c031a2bf26a4b1246390a65be0aa35060363168374f

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 @@ -128,14 +129,22 @@ test-suite polysemy-test
InspectorSpec
InterceptSpec
OutputSpec
Plugin.BadSpec
Plugin.DoctestSpec
Plugin.ExampleSpec
Plugin.LegitimateTypeErrorSpec
Plugin.MultipleVarsSpec
Plugin.PluginSpec
Plugin.TypeErrors
Plugin.VDQSpec
ThEffectSpec
TypeErrors
WriterSpec
Paths_polysemy
hs-source-dirs:
test
default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax
ghc-options: -threaded -rtsopts -with-rtsopts=-N
ghc-options: -threaded -rtsopts -with-rtsopts=-N -fplugin=Polysemy.Plugin
build-tool-depends:
hspec-discover:hspec-discover >=2.0
build-depends:
Expand All @@ -148,6 +157,8 @@ test-suite polysemy-test
, inspection-testing >=0.4.2 && <0.5
, mtl >=2.2.2 && <3
, polysemy
, polysemy-plugin >=0.2.3.0
, should-not-typecheck >=2.1.0 && <3
, stm >=2 && <3
, syb >=0.7 && <0.8
, template-haskell >=2.12.0.0 && <3
Expand Down Expand Up @@ -182,6 +193,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
Loading