[web-devel] Proposal: http-types

Christian Maeder Christian.Maeder at dfki.de
Thu Feb 3 19:41:58 CET 2011

Am 03.02.2011 17:47, schrieb Aristid Breitkreuz:
> I don't see how it follows that there will be lots of repetitions of
> similar code. Please explain why you think this occurs, and why it is
> presumably hard to avoid.

Maybe it is no big deal, if you basically use "show" (and even parsing
could be done using "show" without many case distinctions).

But in "instance Show RequestMethod" of
all constructors must be covered and your derived instance is wrong for
the "Custom" or "OtherMethod" variant.

> In my, possibly naïve, view, you only need to implement
> methodToByteString once, and methodToString can be implemented as
> B8.unpack . methodToByteString.

Sure, that's no big deal.

>     You loose (possibly faster and shorter) pattern matching, but I think it
>     is just as good to use predefined constants and "==" for comparisons.
> With my Method type you also get case-insensitivity for free. :-) And it
> removes the temptation of just writing "PUT" instead of, say,
> HTTP.methodPut. (You can get non-standard methods with
> byteStringToMethod, which is a total function.)

Case-insensitive testing is also no big deal. (Write your own equality.)
Surely, something like HTTP.methodPut should be used, but
(byteStringToMethod "PUT") will also type-check and only give you a
run-time error.

As an alternative, I've attached my version of request methods just for
illustration purposes. The constructor is not exported, therefore you
can only create upper-case strings. My methodList is enough to create
rqMethodMap or your methodListA. (The data type can be a newtype.)

Cheers Christian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReqMeth.hs
Type: text/x-haskell
Size: 825 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110203/61d4f9ed/attachment.hs>

More information about the web-devel mailing list