[web-devel] A light-weight web framework
David House
dmhouse at gmail.com
Thu Apr 5 08:50:34 EDT 2007
On 30/03/07, Chris Eidhof <chris at eidhof.nl> wrote:
> I'm interested in seeing something like this too. However, I am a big
> fan of DSL, especially if they're designed correctly. The crux to
> having a good DSL is thinking: "How do I *really* want to write
> this?", and starting from there on. I haven't really thought about
> those things for a web-framework yet.
I'd agree with this. Haskell is astonishingly expressive and can
support all kinds of levels of EDSLs. I've been writing forum software
in Haskell and came across this decision: do I write my templates in
HTML + some code or in Haskell? I couldn't really see any
disadvantages to the latter, and the advantages were obviously that I
got all the traditional Haskell functions and features, and so on. I
still maintain a fairly strict MVC structure within the application;
the controllers compute the necessary parameters for the templates and
pass them in.
For reference, here's one of my templates:
-- | The 'V' monad, in which our viewers execute.
type V a = WriterT ViewOut (Reader ViewEnv) a
type Viewer = V Html
-- | View the public profile of a user.
vUser :: User -> Viewer
vUser u = do
tell $ VO { voTitle = usrDisplay u,
voBreadcrumbs = singleton indexLink }
usr <- asks veUser
let hdr = h2 << usrDisplay u
dfns = [("Name: ", primHtml $ usrDisplay u),
("Registered at: ", primHtml $ renderCalTime (usrRegistered u)),
("Url: ", toHtml $ hotlink (usrUrl u) << usrUrl u),
("Blurb: ", primHtml $ usrBlurb u)]
del = whenPermitted usr RmUser $
hotlink (userUrl u ++ "/delete") << "Delete user"
return $ hdr +++ defList dfns +++ cappedOps [del]
--
-David House, dmhouse at gmail.com
More information about the web-devel
mailing list