Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax What does $$ mean in Haskell?

Tags:

syntax

haskell

"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?

like image 803
Toymakerii Avatar asked Dec 22 '11 13:12

Toymakerii


2 Answers

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.

like image 125
Heinrich Apfelmus Avatar answered Oct 27 '22 06:10

Heinrich Apfelmus


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.

like image 29
Geheimdienst Avatar answered Oct 27 '22 05:10

Geheimdienst