What's this [f| data |] ??

Hi. I'm trying to get into haskell in my free time. I have already covered some syntax, but there's plenty to do yet, and when I'm consulting other people's stuff, I find lots of unknown constructs to me, which turns harder to lookup for, due to the very "symbolic" nature of Haskell. For instance, on this http://www.yesodweb.com/blog/2012/04/yesod-js-todo they have a few constructs like this: |mkYesod "App" [parseRoutes| /HomeR GET /todoTodosR GET PUT /todo/#TodoId TodoR GET DELETE |]| It seems that the inline text is going to be fed to parseRoutes. How does that constructs work (links?)? I already know list comprehensions which appear to be related with this. Thanks.

parseRoutes is a quasiquoter [1]. It uses a type-safe metaprogramming language called Template Haskell [2] to parse a string as a Route (e.g., HomeR is a Route describing the base resource). You can see the source here [3]. I'm pretty new with Yesod, myself, so I'm sure someone else will give you a more in depth description shortly. [1]: http://www.haskell.org/haskellwiki/Quasiquotation [2]: http://www.haskell.org/haskellwiki/Template_Haskell [3]: http://hackage.haskell.org/packages/archive/yesod-routes/1.0.1.2/doc/html/sr... On Jul 3, 2012, at 10:10 PM, Carlos J. G. Duarte wrote:
Hi. I'm trying to get into haskell in my free time. I have already covered some syntax, but there's plenty to do yet, and when I'm consulting other people's stuff, I find lots of unknown constructs to me, which turns harder to lookup for, due to the very "symbolic" nature of Haskell.
For instance, on this http://www.yesodweb.com/blog/2012/04/yesod-js-todo they have a few constructs like this:
mkYesod "App" [parseRoutes| / HomeR GET
/todo TodosR GET PUT
/todo/# TodoId TodoR GET DELETE
|]
It seems that the inline text is going to be fed to parseRoutes. How does that constructs work (links?)? I already know list comprehensions which appear to be related with this.
Thanks. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

This is quasiquoting. It is a pretty advanced topic, but it allows
you to take an arbitrary string and parse it with a quasiquoter of
your choice (in this case, parseRoutes) into some structure or
another. Yesod uses it all over the place to generate html,
javascript, routing tables, and such.
On Tue, Jul 3, 2012 at 10:10 PM, Carlos J. G. Duarte
Hi. I'm trying to get into haskell in my free time. I have already covered some syntax, but there's plenty to do yet, and when I'm consulting other people's stuff, I find lots of unknown constructs to me, which turns harder to lookup for, due to the very "symbolic" nature of Haskell.
For instance, on this http://www.yesodweb.com/blog/2012/04/yesod-js-todo they have a few constructs like this:
mkYesod "App" [parseRoutes| / HomeR GET /todo TodosR GET PUT /todo/#TodoId TodoR GET DELETE |]
It seems that the inline text is going to be fed to parseRoutes. How does that constructs work (links?)? I already know list comprehensions which appear to be related with this.
Thanks.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Wed, Jul 04, 2012 at 03:10:59AM +0100, Carlos J. G. Duarte wrote:
Hi. I'm trying to get into haskell in my free time. I have already covered some syntax, but there's plenty to do yet, and when I'm consulting other people's stuff, I find lots of unknown constructs to me, which turns harder to lookup for, due to the very "symbolic" nature of Haskell.
For instance, on this http://www.yesodweb.com/blog/2012/04/yesod-js-todo they have a few constructs like this:
|mkYesod "App" [parseRoutes| /HomeR GET /todoTodosR GET PUT /todo/#TodoId TodoR GET DELETE |]|
It seems that the inline text is going to be fed to parseRoutes. How does that constructs work (links?)? I already know list comprehensions which appear to be related with this.
It does kind of look like a list comprehension, but it's actually entirely unrelated -- it's quasiquotation: http://www.haskell.org/haskellwiki/Quasiquotation -Brent

Four answers! Sorry, but according to Gmail I won by 10 minutes =P. Cheers, =) -- Felipe.

On Tue, Jul 3, 2012 at 11:10 PM, Carlos J. G. Duarte
For instance, on this http://www.yesodweb.com/blog/2012/04/yesod-js-todo they have a few constructs like this:
mkYesod "App" [parseRoutes| / HomeR GET /todo TodosR GET PUT /todo/#TodoId TodoR GET DELETE |]
It seems that the inline text is going to be fed to parseRoutes. How does that constructs work (links?)? I already know list comprehensions which appear to be related with this.
That's a Template Haskell (TH) quasi-quotation. The 'parseRoutes' function is the quasi-quoter. Check [1] and [2] for starters =). Also, don't be afraid to ask questions on the Yesod mailing list (of which I'm a subscriber, too). [1] http://www.haskell.org/haskellwiki/Quasiquotation [2] http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.htm... Cheers, -- Felipe.
participants (5)
-
Brent Yorgey
-
Carlos J. G. Duarte
-
David McBride
-
Felipe Almeida Lessa
-
Jack Henahan