Personal tools


From HaskellWiki

Revision as of 05:50, 2 February 2009 by Ashalkhakov (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


1 What is UrlDisp

1.1 Problem statement

URLs are everywhere on the web. Most of them, however, are hard to remember, because they are meaningless for humans. This is wrong, however: URLs are a part of user interface, and therefore should be kept simple, meaningful and memorizeable.

1.2 Solution

UrlDisp provides (Fast)CGI programs a minimalistic domain-specific parser for URLs.

Hierarchical part of the URL is tokenized and matched against rules defined using UrlDisp combinators. Every rule consists of, basically, a predicate and a CGI action. Once a predicate is true, an action is performed; otherwise, alternatives are tried in order. The matching algorithm is backtracking.

2 Usage examples

A regular CGI action looks like this:

output "hello, world!"

Adding a predicate:

-- if URL matches /hello, then output "hello, world!"
h |/ "hello" *> output "hello, world!"

More examples:

-- if URL contains /hello, output "woot, it works!", otherwise check for
-- /foo
(h |/ "hello" *> output "woot, it works!") <|> (h |/ "foo" *> output "foo")

As you can see, the |/ combinator matches current token against it's right operand. h is a special predicate that matches anything, it is used to begin a string of combinators.

One can also match against

  • URL parameters,
  • HTTP methods,
  • and also convert token into a variable which is an instance of Read

There's also an API which is believed to be more human-readable.