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

Add Control.Monad.IO.Class.MonadIO instances for monads in GeniusYield.TxBuilder.IO (GYTxGameMonadIO, GYTxMonadIO, etc.) #377

Closed
jaredponn opened this issue Dec 25, 2024 · 4 comments

Comments

@jaredponn
Copy link

Is your feature request related to a problem? Please describe.
I'm always frustrated when I'd like to do arbitrary IO in the monads provided in https://haddock.atlas-app.io/GeniusYield-TxBuilder-IO.html (e.g. GYTxMonadIO) and since these aren't instances of MonadIO(https://hackage.haskell.org/package/base-4.20.0.0/candidate/docs/Control-Monad-IO-Class.html) we can't do arbitrary IO in these monads.

Describe the solution you'd like
I would love it if MonadIO instances were provided for the aforementioned monads. Those monads run in the IO monad anyways, so I don't think this is harmful.

Describe alternatives you've considered
Since running the aforementioned monads runs in IO in the end anyways, one could do something like

do
  blah <- runGYTxMonadIO .... <some computation>
  blargh <- randomIOAction
  runGYTxMonadIO ... <some other computation>

to achieve the same effect as doing something like the following (assuming the MonadIO instances are implemented)

do
  runGYTxMonadIO .... do 
   blah <- <some computation>
   blargh <- liftIO $ randomIOAction
   <some other computation>

Additional context
Not sure if more context is needed, but would be happy to provide any context required :)

@jaredponn
Copy link
Author

jaredponn commented Dec 25, 2024

Actually nevermind, this appears to be an undesired feature with this comment over here:

{- | INTERNAL USAGE ONLY
Do not expose a 'MonadIO' instance. It allows the user to do arbitrary IO within the tx monad.
-}
ioToQueryMonad :: IO a -> GYTxQueryMonadIO a
ioToQueryMonad ioAct = GYTxQueryMonadIO $ const ioAct

Closing, since it seems like this is something that will never be implemented, but there's a workaround below

@sourabhxyz
Copy link
Member

Does following solve your use case? We provide more information in this release note.

import           GeniusYield.Unsafe                    (unsafeIOToQueryMonad, unsafeIOToTxBuilderMonad)

instance MonadIO GYTxQueryMonadIO where
    liftIO = unsafeIOToQueryMonad

instance MonadIO GYTxBuilderMonadIO where
    liftIO = unsafeIOToTxBuilderMonad

@jaredponn
Copy link
Author

Oh thank you! That does solve my use case! Merry Christmas / happy holidays btw ;)

@sourabhxyz
Copy link
Member

Glad to hear that, and merry Christmas / holidays to you as well mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants