{"id":12842,"date":"2016-01-31T13:23:00","date_gmt":"2016-01-31T12:23:00","guid":{"rendered":"https:\/\/touk.pl\/blog\/?guid=4f370455bb65a59604922178b6edecaf"},"modified":"2023-04-27T11:30:50","modified_gmt":"2023-04-27T09:30:50","slug":"easy-hoogle-usage-from-bash","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2016\/01\/31\/easy-hoogle-usage-from-bash\/","title":{"rendered":"Easy Hoogle usage from bash"},"content":{"rendered":"<h2 id=\"what-is-hoogle\">What is <code>hoogle<\/code>?<\/h2>\n<p><a href=\"https:\/\/www.haskell.org\/hoogle\/\">Hoogle<\/a> is Google for searching of Haskell functions. You could ask it for function name or its signature. There is available command <code>hoogle<\/code>, which could be installed using <a href=\"http:\/\/docs.haskellstack.org\/en\/stable\/README.html\"><code>stack<\/code><\/a>:<br \/>\n    $ stack install hoogle<\/p>\n<h2 id=\"using-hoogle-from-command-line-using-hoogle-from-command-line-to\">Using <code>hoogle<\/code> from command line {#using-hoogle-from-command-line} To<\/h2>\n<p><code>hoogle<\/code> a function you could just pass it as parameter:<br \/>\n    $ hoogle fmap<br \/>\n    Prelude fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b<br \/>\n    Data.Functor fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b<br \/>\n    Control.Monad fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b<br \/>\n    Control.Monad.Instances fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b<br \/>\n    Data.Traversable fmapDefault :: Traversable t =&gt; (a -&gt; b) -&gt; t a -&gt; t b<br \/>\n    Network.Stream fmapE :: (a -&gt; Result b) -&gt; IO (Result a) -&gt; IO (Result b) or pass its signature:<\/p>\n<pre><code>$ hoogle \"(a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]\"\r\nPrelude zipWith :: (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]\r\nData.List zipWith :: (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]\r\nControl.Applicative liftA2 :: Applicative f =&gt; (a -&gt; b -&gt; c) -&gt; f a -&gt; f b -&gt; f c\r\nControl.Monad liftM2 :: Monad m =&gt; (a1 -&gt; a2 -&gt; r) -&gt; m a1 -&gt; m a2 -&gt; m r\r\nPrelude scanl :: (a -&gt; b -&gt; a) -&gt; a -&gt; [b] -&gt; [a]\r\nData.List scanl :: (a -&gt; b -&gt; a) -&gt; a -&gt; [b] -&gt; [a]\r\nPrelude scanr :: (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; [b]\r\nData.List scanr :: (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; [b]\r\nData.List deleteFirstsBy :: (a -&gt; a -&gt; Bool) -&gt; [a] -&gt; [a] -&gt; [a]\r\nData.List intersectBy :: (a -&gt; a -&gt; Bool) -&gt; [a] -&gt; [a] -&gt; [a]\r\n... But it shows only list of the signatures of the functions. Sometimes we want to see more information about function. If you use option \r\n<\/code><\/pre>\n<p><code>-i<\/code>, then additional information will be shown:<br \/>\n    $ hoogle -i &#8220;(a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]&#8221;<br \/>\n    Prelude zipWith :: (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]\n<pre><code>zipWith generalises zip by zipping with the function given as the first argument, instead of a tupling function. For example, zipWith (+) is applied to two lists to produce the list of corresponding sums.\r\n\r\nFrom package base\r\nzipWith :: (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c] And again it is not enough, because it shows only documentation of first function from the list. We have to move a counter to see documentation of further functions, e. g. to show information about third item from the list: \r\n\r\n$ hoogle -i -s 3 \"(a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]\"\r\nControl.Applicative liftA2 :: Applicative f =&gt; (a -&gt; b -&gt; c) -&gt; f a -&gt; f b -&gt; f c\r\n\r\nLift a binary function to actions.\r\n\r\nFrom package base\r\nliftA2 :: Applicative f =&gt; (a -&gt; b -&gt; c) -&gt; f a -&gt; f b -&gt; f c\r\n<\/code><\/pre>\n<h2 id=\"easier-hoogle-usage-in-bash-easier-hoogle-usage-in-bash-it-is-cumbersome-to-count-each-time-you-want-to-read-info-about-further-functions-so-i-have-prepared-bash-function-which-makes-it-easier-to\">Easier <code>hoogle<\/code> usage in <code>bash<\/code> {#easier-hoogle-usage-in-bash} It is cumbersome to count each time you want to read info about further functions, so I have prepared bash function which makes it easier. To search for function type:<\/h2>\n<pre><code>$ hoog \"(a-&gt;b) -&gt; f a -&gt; f b\"\r\n1) Data.Traversable fmapDefault :: Traversable t =&gt; (a -&gt; b) -&gt; t a -&gt; t b\r\n2) Prelude fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n3) Data.Functor fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n4) Control.Monad fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n5) Control.Monad.Instances fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n6) Data.Functor (&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n7) Control.Applicative (&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b Each function will have its counter at the beginning and just add its number at the end of command to show more information about specific function: \r\n\r\n$ hoog \"(a-&gt;b) -&gt; f a -&gt; f b\" 6\r\nSearching for: (a -&gt; b) -&gt; f a -&gt; f b\r\nData.Functor (&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n\r\nAn infix synonym for fmap.\r\n\r\nFrom package base\r\n(&lt;$&gt;) :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b\r\n<\/code><\/pre>\n<h2 id=\"how-to-install-hoog-command-how-to-install-hoog-command-command-is-available\">How to install <code>hoog<\/code> command? {#how-to-install-hoog-command} Command is available<\/h2>\n<p><a href=\"https:\/\/gist.github.com\/alien11689\/bbdb7f6f8f76425a8526\">here<\/a>. To use this command just add it to your <code>~\/bashrc<\/code> file.<\/p>\n","protected":false},"excerpt":{"rendered":"What is hoogle? Hoogle is Google for searching of Haskell functions. You could ask it for function name&hellip;\n","protected":false},"author":54,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[114,553],"class_list":{"0":"post-12842","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-functional-programming","8":"tag-haskell"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/54"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=12842"}],"version-history":[{"count":7,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12842\/revisions"}],"predecessor-version":[{"id":15668,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12842\/revisions\/15668"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=12842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=12842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=12842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}