Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What manner of Haskell syntax is used in [$parseRoutes|/ Home GET|]?

I found this code on the front page of the Yesod project:

import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
instance Yesod HelloWorld where approot _ = ""
getHome = applyLayout [$hamlet|%h1 Hello World|]
main = toWaiApp HelloWorld >>= basicHandler 3000

What language features are used in [$parseRoutes|/ Home GET|] and [$hamlet|%h1 Hello World|] to get the $, |, / and % symbols working, and what do the symbols do?

like image 800
qomp Avatar asked Jul 19 '10 23:07

qomp


People also ask

What does () mean in Haskell?

() is very often used as the result of something that has no interesting result. For example, an IO action that is supposed to perform some I/O and terminate without producing a result will typically have type IO () .

What is pattern matching Haskell?

Overview. We use pattern matching in Haskell to simplify our codes by identifying specific types of expression. We can also use if-else as an alternative to pattern matching. Pattern matching can also be seen as a kind of dynamic polymorphism where, based on the parameter list, different methods can be executed.

What type of binding does Haskell use?

Haskell uses a traditional Hindley-Milner polymorphic type system to provide a static type semantics [4, 6], but the type system has been extended with type classes (or just classes) that provide a structured way to introduce overloaded functions. A class declaration (Section 4.3.

What type of programming language is Haskell?

Haskell (/ˈhæskəl/) is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation.


1 Answers

Those would be a Quasiquotation. It's a way to use Template Haskell to embed another language into Haskell. The quasiquotes 'parseRoutes and hamlet define how to parse and interpret what is inside the bracket [$FOO| ... ]. Many more details at the link above.

like image 149
Jacques Carette Avatar answered Nov 15 '22 10:11

Jacques Carette