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

How to combine two different r MonadReaders ? #150

Open
diqye opened this issue Apr 28, 2024 · 1 comment
Open

How to combine two different r MonadReaders ? #150

diqye opened this issue Apr 28, 2024 · 1 comment

Comments

@diqye
Copy link

diqye commented Apr 28, 2024

I wrote some code as below

testa :: (MonadReader Int m, MonadReader Char m, MonadIO m) => m ()
testa = do
    i <- ask
    c <- ask
    liftIO $ do
        print (i :: Int)
        print (c :: Char)

runTesta :: IO ()        
runTesta = flip runReaderT 100 $  flip runReaderT 'H' testa

When I run, it will be appear some errors
image

@kozross
Copy link
Collaborator

kozross commented Apr 28, 2024

Due to the functional dependency on MonadReader, you can't have any m with two different environments like that. You'd have to do something like a MonadReader (Char, Int) m constraint, then ask would get you both.

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