Re: API for looking-up/retrieving Haddock comments?

2012-08-08 Thread Simon Marlow

On 04/08/2012 08:33, Herbert Valerio Riedel wrote:

Simon Hengel s...@typeful.net writes:

[...]


I have the following in my .ghci:

 -- hoogle integration
 :def hoogle \q - return $ :! hoogle --color=true --count=15   \ ++ q ++ 
\
 :def doc\q - return $ :! hoogle --color=true --info   \ ++ q ++ 
\


[...]

thanks, this already looks very promising; there's just a few minor issues
I'm a bit dissatisfied with the GHCi integration:

  1. it doesn't take into account the currently visible module namespaces that 
GHCi
 has currently loaded (as opposed to `:info` and `:type`):

,
| Prelude import Data.IntMap
|
| Prelude Data.IntMap :info fromList
| fromList :: [(Key, a)] - IntMap a -- Defined in `Data.IntMap'
|
| Prelude Data.IntMap :type  fromList
| fromList :: [(Key, a)] - IntMap a
|
| Prelude Data.IntMap :doc fromList
| Searching for: fromList
| Data.HashTable fromList :: Eq key = (key - Int32) - [(key, val)] - IO 
(HashTable key val)
|
| Convert a list of key/value pairs into a hash table. Equality on keys
| is taken from the Eq instance for the key type.
|
| From package base
| fromList :: Eq key = (key - Int32) - [(key, val)] - IO (HashTable key val)
|
| Prelude Data.IntMap
`

  2. tab-completion (as it works for `:type` and `:doc`) doesn't extend
 to `:doc`


I guess both items could be improved upon by extending GHCi to provide
an additional `:def` facility tailored to Haskell symbols allowing to
pass more meta-information (such as package and module information) into
the resulting command string... would something like that have any
chance of being accepted upstream?


I think it would make more sense to just add :doc to the GHCi front-end, 
relying on the user having already installed hoogle.  We could give a 
sensible error message if you don't have Hoogle installed.


Cheers,
Simon

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: API for looking-up/retrieving Haddock comments?

2012-08-08 Thread Simon Hengel
 I guess both items could be improved upon by extending GHCi to provide
 an additional `:def` facility tailored to Haskell symbols allowing to
 pass more meta-information (such as package and module information) into
 the resulting command string... would something like that have any
 chance of being accepted upstream?
 
 I think it would make more sense to just add :doc to the GHCi
 front-end, relying on the user having already installed hoogle.  We
 could give a sensible error message if you don't have Hoogle
 installed.

I think it would be awesome if you could extend GHCi's functionality
with plug-ins.  Mainly, because it would make it easy to experiment with
ways to optimize your workflow.

One use case I have in mind is running Hspec tests from GHCi.  Currently
that requires me to:

(a) Reload the module:

   ghci :reload

(b) Check the output for compile errors.

(c) Only if there were no compile errors, run the tests:

ghci hspec spec

Here it would be nice to have a custom :hspec command within GHCi, that
does all the required steps.  But GHCi's current mechanism for defining
commands is not powerful enough.  (It's possible to define a sequence of
commands, but it's not possible to check for the result of (a) and only
conditionally do (c)).

From a users point of view I'd love to have a fancy GHCi monad to define
commands (with access to all the built-ins, and means to define
completion, etc.), and a mechanism to hook those commands into a running
GHCi process.

How hard would it be to implement something like this?

Cheers,
Simon

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: API for looking-up/retrieving Haddock comments?

2012-08-04 Thread Herbert Valerio Riedel
Simon Hengel s...@typeful.net writes:

[...]

 I have the following in my .ghci:

 -- hoogle integration
 :def hoogle \q - return $ :! hoogle --color=true --count=15   \ ++ q 
 ++ \
 :def doc\q - return $ :! hoogle --color=true --info   \ ++ q 
 ++ \

[...]

thanks, this already looks very promising; there's just a few minor issues
I'm a bit dissatisfied with the GHCi integration:

 1. it doesn't take into account the currently visible module namespaces that 
GHCi
has currently loaded (as opposed to `:info` and `:type`):

,
| Prelude import Data.IntMap
| 
| Prelude Data.IntMap :info fromList
| fromList :: [(Key, a)] - IntMap a-- Defined in `Data.IntMap'
| 
| Prelude Data.IntMap :type  fromList
| fromList :: [(Key, a)] - IntMap a
| 
| Prelude Data.IntMap :doc fromList
| Searching for: fromList
| Data.HashTable fromList :: Eq key = (key - Int32) - [(key, val)] - IO 
(HashTable key val)
| 
| Convert a list of key/value pairs into a hash table. Equality on keys
| is taken from the Eq instance for the key type.
| 
| From package base
| fromList :: Eq key = (key - Int32) - [(key, val)] - IO (HashTable key val)
| 
| Prelude Data.IntMap 
`

 2. tab-completion (as it works for `:type` and `:doc`) doesn't extend
to `:doc`


I guess both items could be improved upon by extending GHCi to provide
an additional `:def` facility tailored to Haskell symbols allowing to
pass more meta-information (such as package and module information) into
the resulting command string... would something like that have any
chance of being accepted upstream?

cheers,
  hvr

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: API for looking-up/retrieving Haddock comments?

2012-08-03 Thread Simon Hengel
 I've been wondering if there have been attempts to provide some
 library/API or similiar facility (other than pointing your web-browser
 to the static Haddock HTML report) for looking up Haddock comments
 associated with Haskell symbols?
 
 As an obvious application: When coding in dynamic languages
 (e.g. Python, Elisp, or GNU R to name a few), I've learned to appreciate
 the ability to lookup up documentation interactively from the
 tab-completing REPL w/o having to switch context/focus to different
 application (as I currently do: I have to switch from GHCi to a
 web-browser and first locate the appropriate package/module and then
 find the symbol I'm interested in).


I have the following in my .ghci:

-- hoogle integration
:def hoogle \q - return $ :! hoogle --color=true --count=15   \ ++ q ++ 
\
:def doc\q - return $ :! hoogle --color=true --info   \ ++ q ++ 
\

Which can be used from GHCi like so:

Prelude :doc map
Searching for: map
Prelude map :: (a - b) - [a] - [b]

map f xs is the list obtained by applying f to each element of xs, i.e.,

 map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
 map f [x1, x2, ...] == [f x1, f x2, ...] 

From package base
map :: (a - b) - [a] - [b]

Have a look at [1].

Cheers,
Simon

[1] http://www.haskell.org/haskellwiki/Hoogle#GHCi_Integration

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users