[web-devel] A light-weight web framework
Johan Tibell
johan.tibell at gmail.com
Thu Mar 29 13:48:33 EDT 2007
Inspired by the ease with which Joe Gregorio put together a framework
in Python using some components [1] I'm inspired to create some
components of my own so the same thing can be done in Haskell. I'm
aiming for creating some thing /really/ simple and I want to start
with writing a templating system or a database wrapper. But first,
what has been done in this area already already? I'm aware of at least
some template like efforts [2]. For the templating system I don't
think I want a DSL like approach (ala Lisp with (body (h1 "Foo")) etc.
but rather a solution where code and templates are kept separate.
Here's a really simple interface.
compileTemplate :: Stringable a => a -> Template
renderTemplate :: (Show a, Stringable b) => Template -> Map Stringable a -> b
Or something along those lines. Compiling the template makes
subsequent rendering faster and ByteString adds even more speed.
With some templating language like so:
<html>
<head>...</head>
<body>
<h1>{{ title }}</h1>
</body>
</html>
'title' is looked up in the Map when the template is rendered. The
other option would be inline Haskell code:
<html>
<head>...</head>
<body>
<h1><% postTitle title %></h1>
</body>
</html>
Where 'title' is a record data type. There's also a middle ground like
with Django's templates that supports restricted inline code. I guess
the restriction is unnecessary in Haskell as we can disallow mutation
of values quite easily (?).
1. http://bitworking.org/news/Why_so_many_Python_web_frameworks
2. http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem
More information about the web-devel
mailing list