[Haskell-cafe] oauth in haskell - reviewers?
Alexander Dunlap
alexander.dunlap at gmail.com
Sat Aug 22 23:08:53 EDT 2009
On Sat, Aug 22, 2009 at 4:36 PM, Diego Souza<dsouza at bitforest.org> wrote:
> Hi all,
>
> I wrote a small library in haskell do deal with oauth authentication. It
> turns out it is my first library in haskell as well. As I'm beginner in
> haskell, I'm asking for a review of someone more experienced/proficient
> before even daring to create a cabal pkg and dist it to hackage. :-)
>
> Any help/comments on this will be highly welcome.
>
> http://projects.bitforest.org/hoauth/
>
> $ darcs get http://projects.bitforest.org/hoauth/
> # should do the trick
>
> Thanks in advance,
> --
> ~dsouza
> yahoo!im: paravinicius
> gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B 9ECE F88E 067F E891 651E
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
Hi,
I'm not familiar at all with OAuth but I have some general suggestions
that might make your code in "Consumer.hs" a bit nicer. These
suggestions also probably apply elsewhere in your code.
- In the Token datatype, you can automatically create the accessor
functions (oath_token, etc.) by using named fields:
data Token
= Request { oath_token :: String, oath_token_secret :: String,
oath_extra :: R.Parameter }
| Access { oath_token :: String, oath_token_secret :: String,
oath_extra :: R.Parameter }
This will create your accessor functions for free, and you get update
syntax to boot. (Google for "haskell named fields" for details.)
- When you have multiple datatype constructors with similar arguments
(as with Token or Request), it may be better to use a Boolean-type
flag saying which one it is (e.g. HTTP or HTTPS) and then a single
datatype with all of the different arguments in it. This may help you
remove code duplication elsewhere.
- I think you can use join from Control.Monad and functions from
Control.Applicative in your "response" function to make it quite a bit
cleaner.
I know this email has been a bit terse; ask if you have any questions
about the above.
Hope that helps,
Alex
More information about the Haskell-Cafe
mailing list