When I use bracket (or rather bracket_, in the example below) inside a runNonDet block the resource is released too early. Is this expected?
(I feel this must be a common question, so apologies if it's answered elsewhere, but I didn't find this precise issue in the documentation, nor from searching the issues here.)
{-# LANGUAGE GHC2021 #-}
{-# LANGUAGE DataKinds #-}
import Control.Applicative ((<|>))
import Polysemy (embed, runM)
import Polysemy.NonDet (runNonDet)
import Polysemy.Resource (bracket_, runResource)
example :: IO [Int]
example =
runM $
runNonDet $
runResource $
bracket_
(embed (putStrLn "Acquired"))
(embed (putStrLn "Released"))
( do
r <- pure 1 <|> pure 2
embed (putStrLn "Used")
pure r
)
-- ghci> example
-- Acquired
-- Used
-- Released
-- Used
-- Released
-- [1,2]
When I use
bracket(or ratherbracket_, in the example below) inside arunNonDetblock the resource is released too early. Is this expected?(I feel this must be a common question, so apologies if it's answered elsewhere, but I didn't find this precise issue in the documentation, nor from searching the issues here.)
{-# LANGUAGE GHC2021 #-} {-# LANGUAGE DataKinds #-} import Control.Applicative ((<|>)) import Polysemy (embed, runM) import Polysemy.NonDet (runNonDet) import Polysemy.Resource (bracket_, runResource) example :: IO [Int] example = runM $ runNonDet $ runResource $ bracket_ (embed (putStrLn "Acquired")) (embed (putStrLn "Released")) ( do r <- pure 1 <|> pure 2 embed (putStrLn "Used") pure r ) -- ghci> example -- Acquired -- Used -- Released -- Used -- Released -- [1,2]