is there way see typeclass definition in ghci specific type?
for example, maybe
defined this:
instance functor maybe fmap f (just x) = (f x) fmap f nothing = nothing
can see in ghci ?
when, use :info
in ghci, this:
prelude> :i maybe data maybe = nothing | -- defined in `data.maybe' instance eq => eq (maybe a) -- defined in `data.maybe' instance monad maybe -- defined in `data.maybe' instance functor maybe -- defined in `data.maybe' instance ord => ord (maybe a) -- defined in `data.maybe' instance read => read (maybe a) -- defined in `ghc.read' instance show => show (maybe a) -- defined in `ghc.show'
in above output, want see how defined in data.maybe instance functor
. anyway see in ghci ?
no, it's not possible – not instances anything. ghc registers compiled version of package, source code won't available ghci.
probably, you'll using stuff hackage; in case it's simple find source code of such instances hoogling module, locating class or data declaration, , clicking on source.
when don't have internet access or whatever else reason can't hoogle online, first need find out in package module included. easiest way that:
$ ghc-pkg find-module data.maybe
/usr/local/haskell/lib/ghc-7.6.2/package.conf.d
base-4.6.0.1
haskell2010-1.1.1.0
~/.ghc/x86_64-linux-7.6.2/package.conf.d
then, said, ghc doesn't know source code these packages located – in fact might not available on system! if you've installed package (or 1 depends on it) cabal install
, there, default in ~/.cabal/packages/hackage.haskell.org/pᴀᴄᴋᴀɢᴇnᴀᴍᴇ
(as compressed archive, that's not big hurdle). within package project folder, can locate module via directory structure, represents module hierarchy.
other packages, example of data.maybe
(package haskell2010
), may have come right installation of ghc, e.g. haskell platform. in case, believe easiest thing search there haddock documentation file. in case,
$ find /usr/local/haskell -name 'data-maybe.html' | head -n1 | xargs firefox
that'll open equivalent hoogle links (but on local hd), can browse source code in user-friendly way.
Comments
Post a Comment