
On Mon, Feb 14, 2011 at 02:10:13PM -0500, Britt Anderson wrote:
I am looking at code from a tutorial that has the following type signature for a function:
getScreen :: MonadReader AppConfig m => m Surface
AppConfig is a data structure that was defined previously. My question is how am I to interpret this type signature? Is it any m belonging to the MonadReader AppConfig class?
Yes. And there will be an instance for MonadReader AppConfig m exactly when m carries around an implicit "read-only" AppConfig value, available for querying with the 'ask' and 'asks' functions.
Since I can't see any instance of the MonadReader Class being defined for MonadReader AppConfig I am puzzled.
Typically what you will see is some concrete monad later being defined in terms of ReaderT AppConfig, which will automatically give it an appropriate MonadReader instance, allowing users of the monad to query the AppConfig.
I would appreciate some clarification or a pointer to a prior discussion of this issue. I have tried to look on my own.
I recommend reading Cale Gibbard's article "How to use monad transformers"... except at the moment I can't seem to find it anywhere. =( -Brent