Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to ask GHCI about where a particular instance is defined?

For example, can I query "where is RWS defined as an instance of MonadState"? I would expect an answer like module (version), source file, line.

like image 430
ron Avatar asked Dec 27 '22 14:12

ron


1 Answers

λ> :info MonadState
...
instance (Monad m, Monoid w) => MonadState s (RWST r w s m)
  -- Defined in `Control.Monad.State.Class'
λ> :i RWS
type RWS r w s = RWST r w s Identity
        -- Defined in `Control.Monad.Trans.RWS.Lazy'
λ> :i RWST
...
instance MonadState s m => MonadState s (Reader.ReaderT r m)
  -- Defined in `Control.Monad.State.Class'
...

You can't get line information, and it only shows modules that are currently loaded, but that's enough to hunt instances down.

like image 83
shachaf Avatar answered May 23 '23 08:05

shachaf