O'Reilly logo

Developing Web Applications with Haskell and Yesod by Michael Snoyman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preface

It’s fair to say that dynamic languages currently dominate the web development scene. Ruby, Python, and PHP are common choices for quickly creating a powerful web application. They give a much faster and more comfortable development setting than standard static languages in the C family, like Java.

But some of us are looking for something more in our development toolbox. We want a language that gives us guarantees that our code is doing what it should. Instead of writing up a unit test to cover every bit of functionality in our application, wouldn’t it be wonderful if the compiler could automatically ensure that our code is correct? And as an added bonus, wouldn’t it be nice if our code ran quickly too?

These are the goals of Yesod. Yesod is a web framework bringing the strengths of the Haskell programming language to the web development world. Yesod not only uses a pure language to interact with an impure world, it allows safe interactions with the outside world by automatically sanitizing incoming and outgoing data. Not only do we avoid basic mistakes such as mixing up integers and strings, it even allows us to statically prevent many cases of security holes like cross-site scripting (XSS) attacks.

Who This Book Is For

In general, there are two groups of people coming to Yesod. The first group is long time Haskell users—already convinced of the advantages of Haskell—who are looking for a powerful framework for creating web applications. The second is web developers who are either dissatisfied with their existing tools, or are looking to expand their horizons into the functional world.

This book assumes a basic familiarity with both web development and Haskell. We don’t use many complicated Haskell concepts, and those we do use are introduced separately. For the most part, understanding the basics of the syntax of the language should be sufficient.

If you want to come up to speed on Haskell, I recommend another wonderful O’Reilly book: Real World Haskell.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This icon signifies a tip, suggestion, or general note.

Caution

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Developing Web Applications with Haskell and Yesod by Michael Snoyman (O’Reilly). Copyright 2012 Michael Snoyman, 978-1-449-31697-6.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://shop.oreilly.com/product/0636920023142.do

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgements

Yesod has been created by an entire community of developers, all of whom have put in significant effort to make sure that the final product is as polished and user-friendly as possible. Everyone from the core development team to the person making an API request on the mailing list has had an impact on bringing Yesod to where it is today.

In particular, I’d like to thank Greg Weber, who has shared the maintenance burden of the project; Kazu Yamamoto and Matt Brown, who transformed Warp from a simple testing server to one of the fastest application servers available today; and Felipe Lessa, Patrick Brisbin, and Luite Stegeman for their numerous contributions across the board.

A big thank you to my editor, Simon St. Laurent, for all of his guidance and support. Mark Lentczner, Johan Tibell, and Adam Turoff provided incredibly thorough reviews of this book, cleaning up many of my mistakes. Additionally, there have been dozens of readers who have looked over the content of this book online, and provided feedback on where either the prose or the message was not coming through clearly—not to mention numerous spelling errors.

But finally, and most importantly, I’d like to thank my wife, Miriam, for enduring all of the time spent on both this book and Yesod in general. She has been my editor and sounding-board, though I’m sure the intricacies of Template Haskell sometimes worked more as a sedative than any meaningful conversation. Without her support, neither the Yesod project nor this book would have been able to happen.

Also, you’ll notice that I use my kids’ names (Eliezer and Gavriella) in some examples throughout the book. They deserve special mention in a Haskell text, since I think they’re the youngest people to ever use the word “monad” in a sentence with their “Transformers: Monads in Disguise.”

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required