Unescaping URLs in Python and Haskell

A while ago I decided that in order to learn Haskell I should make an attempt to stop reaching for Python whenever I needed to solve a “small problem” and use Haskell instead. This morning I found a need to unescape URLs inside Vim and I didn’t catch myself until after I had written the following Python code:

After a little bit of cursing I started browsing Hoogle and after bit of searching I found the Network.URI module. My Haskell solution ended up looking like this:

Short, sweet, and easy to understand, I think.

In case you want to go the other direction, i.e. to escape strings in Haskell then combining escapeURIString and isUnreserved is the right thing to do.


For a quick-‘n’-dirty app like this one, you don’t have to bother with the module or type declarations:

Because shorter can be sweeter. :)

N.B. Function application binds more tightly than anything else, so you never need brackets around it except to override its associativity.

Leave a comment