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 Sequence instead of List in Floodgate #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions src/Polysemy/Floodgate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Polysemy.Floodgate
) where

import Control.Monad
import Data.Sequence (Seq, (|>))
import GHC.Types
import Polysemy
import Polysemy.State
Expand All @@ -36,17 +37,17 @@ makeSem ''Floodgate
runFloodgate
:: Sem (Floodgate ': r) a
-> Sem r a
runFloodgate = fmap snd . runState @[Any] [] . reinterpretH
runFloodgate = fmap snd . runState @(Seq Any) Seq.empty . reinterpretH
( \case
Hold m -> do
m' <- fmap void $ runT m
-- These 'Any's are here because the monadic action references 'r', and
-- if we exposed that, 'r' would be an infinite type
modify (unsafeCoerce @_ @Any (raise $ runFloodgate m') :)
modify (unsafeCoerce @_ @Any (raise $ runFloodgate m') |>)
getInitialStateT

Release -> do
ms' <- gets @[Any] (fmap unsafeCoerce . reverse)
ms' <- gets @(Seq Any) (fmap unsafeCoerce)
sequence_ ms'
getInitialStateT
)
Expand Down