10

I have been trying to find in the Haskell reference the use of this:

getHomeR = defaultLayout $ do
    setTitle "My Awesome Site"
    $(widgetFile "home")

Specifically:

$(widgetFile "home")

I know that the $ operator gives precedence to whatever is to the right of it, but I have not been able to comprehend the usage of $(). Anyone?

AJF
  • 11,767
  • 2
  • 37
  • 64
Luis Dos Reis
  • 393
  • 3
  • 15

1 Answers1

10

This is not using the $ application operator, but is involving a Template Haskell slice.

Very roughly, widgetFile "home" is code which is run at compile time: it generates Haskell code, which is then compiled as usual. It's a form of metaprogramming in Haskell.

chi
  • 111,837
  • 3
  • 133
  • 218
  • I see so it has nothing to do with the $ operator. `widgetFile "home"` will then be responsible for generating this code on the fly at compile time? – Luis Dos Reis Jun 28 '15 at 17:28
  • 1
    @LuisDosReis Yes. It might for instance access an external file, process it, and generate some Haskell code depending on it. This can be used to obtain a vastly generalized `#include`, for instance, where the included file can use a different syntax. – chi Jun 28 '15 at 17:30
  • Oh interesting so I can apply metaprogramming at manipulating different languages too. – Luis Dos Reis Jun 28 '15 at 17:36