[Haskell-cafe] using phantom types to validate html
Mathijs Kwik
bluescreen303 at gmail.com
Sat Jun 6 14:41:57 EDT 2009
Hi all,
Please have a look at
http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=2575#a2575
I wanted to use the typesystem to mandate businesslogic (in this case
w3c validation rules).
Thanks to some helpful people in #haskell I learned a bit about phantom types.
Please let me know if I implemented them correctly.
Also this little experiment raises some questions:
The code becomes very verbose if there are more elements added or more
rules to check.
Since repetitive code can be a source of error, and hellish to
maintain, I would like to know if there's some way to get this
generated, or maybe there's some meta-programming stuff I don't know
about.
Another thing I can't figure out yet is how to do more advanced
validation rules like "an html element cannot have 2 head sections",
or (made up) "a span element isn't allowed to be a child(any level
deep) of a p element".
I think this would ask for an exponentially growing number of strange
types and classes. Am I right?
Just to be clear: this is just some practice to use the typesystem.
I'm well aware that just using runtime validation checks will be a lot
easier and clearer in most cases.
Thanks,
Mathijs
More information about the Haskell-Cafe
mailing list