19

"Ugh," you might think... "Another syntax question, here let me google that for you noob." But alas! I have googled it, and I am still stumped!

Found in this code from the yesod blog

import System.IO
import Data.Enumerator
import Data.Enumerator.Binary

main =
    withFile "output.txt" WriteMode $ \output ->
    run_ $ enumFile "input.txt" $$ iterHandle output 

However the "$$" operator is new to me. The Haskell 2010 report only mentions it once as an operator symbol. What does it do?

Toymakerii
  • 1,510
  • 2
  • 12
  • 26
  • 4
    Here at StackOverflow, we encourage noob questions, as long as you put effort into making clear what your question is and also put moderate effort into googling for the answer and avoiding dupes. Your question is clear, unique, and relevant, so stop worrying and ask away! – Dan Burton Dec 22 '11 at 17:31
  • 4
    Thanks Dan! Normally my questions feel more complex than a simple operator so I was a touch nervous that I had missed something, RTFM and all. – Toymakerii Dec 22 '11 at 19:29
  • 1
    You may have googled it, but have you Hoogled it? – AJF Jan 13 '15 at 19:28

3 Answers3

21

In Haskell, operators like $$ are not part of the syntax, they are user-definable functions. Hence, you need to look up the API documenation for Yesod to see what $$ is. In particular, the function $$ from your example is documented here.

Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67
  • 2
    Note that enumerator is not a Yesod library, so looking at the Yesod documentation wouldn't help in this instance :) Happily, plugging `Data.Enumerator` into Hoogle produces the right package, although it doesn't appear as a result for `($$)`... – ehird Dec 22 '11 at 14:08
  • 1
    Another option is [hayoo](http://holumbus.fh-wedel.de/hayoo/hayoo.html). Funnily, that finds results for "($$", but neither for "$$" nor for "($$)". – Daniel Fischer Dec 22 '11 at 14:47
  • Dang! I would have not thought of this on my own! I just assumed it was a built-in when it was referenced in the report. Are there other operators that are common? Perhaps style guides on what kind of operators should be used for different types of functions? – Toymakerii Dec 22 '11 at 19:26
  • 1
    @Toymakerii: What do you mean with style guides? Truth to be said, `$$` is not very common. The really common operators are defined in the really common libraries, like `$` or `>>=` from the Prelude or `<*>` from `Control.Applicative`. – Heinrich Apfelmus Dec 23 '11 at 09:01
  • 1
    @Toymakerii: Where does the Report reference `($$)`? I doubt it's referring to it as an operator; no standard library defines it, so it has no particular reason to. – ehird Dec 23 '11 at 13:13
  • @ehird its a brief mention as an example of an "operator symbol" in section 3.2 – Toymakerii Dec 24 '11 at 12:10
  • @HeinrichApfelmus I suppose that answers my question! Often I find the Haskell community likes conventions and I wanted to make sure I didnt miss one. – Toymakerii Dec 24 '11 at 12:15
  • @Toymakerii: Ah, concerning conventions, they usually come from the `Prelude` and the monad / applicative functor stuff. – Heinrich Apfelmus Dec 24 '11 at 14:32
6

There's Hoogle, which is pretty good but unfortunately doesn't know many packages.

Hayoo knows much more, but its interface seems quirky, and it doesn't seem to offer a command-line tool like hoogle does.

If you have an idea what package you're dealing with, you can directly go to its documentation—e.g. the docs of the enumerator package, with the module list at the bottom. Also, these docs always have an index, and let you view the source code via the source links.

As a last resort, use cabal unpack enumerator and grep through the code.

Geheimdienst
  • 109
  • 1
  • 1
    Google knows more than you might think. Just add `+somepkg` to your search. – Thomas M. DuBuisson Dec 22 '11 at 18:58
  • @Thomas Trouble is if you don't know which package you need. Btw, ITYM hoogle, not Google. – Daniel Fischer Dec 22 '11 at 20:12
  • @DanielFischer Right. my phone thinks hoogle == google, sorry. Oh, and in this particular case we did know which set of packages to look in, (but I'll certainly agree - you are right in general and it would be nice if web hoogle included more packages by default) – Thomas M. DuBuisson Dec 22 '11 at 22:15
  • @Thomas That, or a button "search all packages you know about", or an option to search all packages in a category (hackage, not CT), "all packages" may create a too big search space. No need to apologize for your phone's auto-correction. Depending on your typo rate it may be better to turn it off if possible, though. – Daniel Fischer Dec 22 '11 at 22:27
2

Just use hoogle and be sure to tell it what packages you are using - it works fine.

http://haskell.org/hoogle/?hoogle=%28%24%24%29+%2Benumerator

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166