I don't understand why this happens:
module Main where
import Control.Monad.Reader
data Config = Config Int
getA :: (Monad m) => ReaderT Config m Int
getA = do
Config a <- ask
return a
readConfig :: Config -> IO Int
readConfig = runReaderT getA
main :: IO ()
main = do
print "Start"
let a = Config 2
b <- readConfig a -- Will be printed
print b
let c = Config 4
print <$> readConfig c -- Silence, nobody complains..
print "Done"
the result is just:
"Start"
2
"Done"
Why is print <$> readConfig a
empty? Even with -Wall
nobody complains about this...
(I tried diff ghc versions in godbolt but the result stays the same)
Edit: Ok, I found an equivalent description of the problem, thx to @chi and @David:
module Main where
test :: IO ()
test = do
print "test"
return ()
main :: IO ()
main = do
let t = test -- equivalent to print <$> readConfig c, is IO (IO ())
test -- equivalent to print b is IO ()
Now, I'm just wanting to know why let t
does not evaluate. From my intuition, it was obvious before but not anymore... But there are answers to this (esp. from Tanner Swett)