<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Haskell on Lorenzo Bolla</title><link>https://lbolla-info.netlify.app/tags/haskell/</link><description>Recent content in Haskell on Lorenzo Bolla</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 10 Oct 2012 00:00:00 +0000</lastBuildDate><atom:link href="https://lbolla-info.netlify.app/tags/haskell/index.xml" rel="self" type="application/rss+xml"/><item><title>URL Counter in GO</title><link>https://lbolla-info.netlify.app/blog/url-counter-in-go/</link><pubDate>Wed, 10 Oct 2012 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/url-counter-in-go/</guid><description>&lt;p&gt;After having tinkered with #haskell for quite a bit, I decided that I needed some rest from theory and esoteric concepts, and a more pragmatic programming language to explore.&lt;/p&gt;
&lt;p&gt;I've spent the last few days refreshing my memories on &lt;a href="http://golang.org/"&gt;Go&lt;/a&gt;: I hadn&amp;rsquo;t touched it for almost 2 years and I must say that I find it changed: for the better.&lt;/p&gt;
&lt;p&gt;Here is a short tutorial on how to write a simple web application in Go, and publish it on &lt;a href="https://developers.google.com/appengine/"&gt;Google App Engine&lt;/a&gt;. The application is not a mere exercise, but scratches an itch I recently had: it counts how many times each of its handlers is hit. So, for example, visiting: &lt;a href="http://go-count-urls.appspot.com/hello"&gt;http://go-count-urls.appspot.com/hello&lt;/a&gt; returns how many times the &lt;code&gt;/hello&lt;/code&gt; handler has been visited. You can use it as a trivial real-time tracker.&lt;/p&gt;</description></item><item><title>Tornado vs. Warp vs. Yesod</title><link>https://lbolla-info.netlify.app/blog/tornado-vs.-warp-vs.-yesod/</link><pubDate>Sun, 02 Sep 2012 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/tornado-vs.-warp-vs.-yesod/</guid><description>&lt;p&gt;Today I tried to benchmark 3 web servers that I've used recently:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://www.tornadoweb.org/"&gt;Tornado&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://hackage.haskell.org/package/warp/"&gt;Warp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.yesodweb.com/"&gt;Yesod&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In fact, these are only *2* web servers, because &lt;code&gt;Yesod&lt;/code&gt; runs on top of Warp and it's a fully fledged web framework, rather than a web server: but this was also the intent of the benchmark, i.e. to measure how slower all its goodies made Yesod with respect to Warp.&lt;/p&gt;
&lt;p&gt;Tornado and Warp are obviously very different web servers (async vs. threaded, interpreted vs. compiled, etc.) but, &lt;a href="http://ziutek.github.com/web_bench/"&gt;who cares&lt;/a&gt;?&lt;/p&gt;</description></item><item><title>hsenv</title><link>https://lbolla-info.netlify.app/blog/hsenv/</link><pubDate>Thu, 29 Mar 2012 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/hsenv/</guid><description>&lt;p&gt;If you have never used &lt;a href="https://github.com/Paczesiowa/hsenv"&gt;hsenv&lt;/a&gt; before, you should. It's basically the Haskell's equivalent of Python's &lt;a href="http://pypi.python.org/pypi/virtualenv"&gt;virtualenv&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can find a &lt;a href="https://github.com/lbolla/hsenv"&gt;tweaked version of hsenv here&lt;/a&gt;: I've relaxed some requirements in order to make it install on newer GHC releases.&lt;/p&gt;
&lt;p&gt;Finally, if when using you hit this error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ hsenv Creating Virtual Haskell directory structure
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Installing GHC Initializing GHC Package database at /home/lollo/work/Unique/.hsenv/ghc_pkg_db
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Copying necessary packages from original GHC package database
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;hsenv: fd:9: hGetContents: invalid argument &lt;span style="color:#f92672"&gt;(&lt;/span&gt;invalid byte sequence&lt;span style="color:#f92672"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;hsenv: thread blocked indefinitely in an MVar operation
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, you have a problem with your locale. Follow the steps &lt;a href="https://wiki.archlinux.org/index.php/Locale#Enabling_necessary_locales"&gt;here&lt;/a&gt;, and retry.&lt;/p&gt;</description></item><item><title>Sudoku solver in Haskell</title><link>https://lbolla-info.netlify.app/blog/sudoku-solver-in-haskell/</link><pubDate>Mon, 27 Feb 2012 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/sudoku-solver-in-haskell/</guid><description>&lt;p&gt;Recently, I've been challenged to write a &lt;a href="http://en.wikipedia.org/wiki/Sudoku"&gt;Sudoku&lt;/a&gt; solver. Not knowing the rules and with only 30 minutes, I needed some help&amp;hellip;&lt;/p&gt;
&lt;p&gt;So, in case someone asks me again, I've implemented the same algorithm in Haskell.&lt;/p&gt;
&lt;script src="https://gist.github.com/1925630.js"&gt; &lt;/script&gt;
&lt;p&gt;I know that &lt;a href="http://www.haskell.org/haskellwiki/Sudoku"&gt;there are already a lot of other solutions&lt;/a&gt;, but, hey, it was fun!&lt;/p&gt;</description></item><item><title>ulint, Universal Lint</title><link>https://lbolla-info.netlify.app/blog/ulint-universal-lint/</link><pubDate>Thu, 05 Jan 2012 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/ulint-universal-lint/</guid><description>&lt;p&gt;I've been using so many code static checkers lately, that I decided to write a wrapper around the ones I use the most. I called it: &lt;a href="https://github.com/lbolla/ulint"&gt;Universal Lint&lt;/a&gt;, &lt;a href="https://github.com/lbolla/ulint"&gt;ulint&lt;/a&gt; for short.&lt;/p&gt;
&lt;p&gt;At the moment, Python, Javascript and Haskell files are supported, but adding new linters/extension is trivial.&lt;/p&gt;
&lt;p&gt;Download it and use it!&lt;/p&gt;</description></item><item><title>HSGrep benchmarking</title><link>https://lbolla-info.netlify.app/blog/hsgrep-benchmarking/</link><pubDate>Wed, 30 Nov 2011 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/hsgrep-benchmarking/</guid><description>&lt;p&gt;Few days ago, &lt;a href="https://lbolla-info.netlify.app/blog/hsgrep-sorted-grep-in-haskell/"&gt;I rewrote &lt;code&gt;sgrep&lt;/code&gt; in Haskell&lt;/a&gt;. I was curious to know how it compares to &lt;a href="http://en.wikipedia.org/wiki/Grep.org"&gt;&lt;code&gt;grep&lt;/code&gt;&lt;/a&gt; in term of execution speed. In particular, I was interested to verify that &lt;code&gt;hsgrep&lt;/code&gt; scales as &lt;code&gt;O(log n)&lt;/code&gt;, instead of &lt;code&gt;O(n)&lt;/code&gt;, with &lt;code&gt;n&lt;/code&gt; being the size of the file analyzed.&lt;/p&gt;
&lt;p&gt;First of all, in order to have similar performance to &lt;code&gt;grep&lt;/code&gt;, I had to convert my original program to use &lt;a href="http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString.html"&gt;Haskell's bytestrings&lt;/a&gt;. &lt;a href="https://github.com/lbolla/HSGrep/tree/bytestring"&gt;You can find the code here&lt;/a&gt;. Testing files are generated with &lt;a href="https://github.com/lbolla/HSGrep/blob/bytestring/data/gendata.hs"&gt;this script&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>HSGrep Sorted grep in Haskell</title><link>https://lbolla-info.netlify.app/blog/hsgrep-sorted-grep-in-haskell/</link><pubDate>Sun, 27 Nov 2011 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/hsgrep-sorted-grep-in-haskell/</guid><description>&lt;p&gt;As an exercise to learn &lt;a href="http://haskell.org/haskellwiki/Haskell"&gt;Haskell&lt;/a&gt;, I wrote a specialized &lt;code&gt;grep&lt;/code&gt; to work on sorted files. It uses &lt;a href="http://en.wikipedia.org/wiki/Binary_search_algorithm"&gt;binary search&lt;/a&gt; to scan a text file and print all the (consecutive) lines that start with a user defined string.&lt;/p&gt;
&lt;p&gt;My program is a rewrite of &lt;a href="http://sourceforge.net/projects/sgrep/"&gt;&lt;code&gt;sgrep&lt;/code&gt;&lt;/a&gt; in &lt;a href="http://haskell.org/haskellwiki/Haskell"&gt;Haskell&lt;/a&gt;: I called it &lt;a href="https://github.com/lbolla/HSGrep"&gt;HSGrep&lt;/a&gt;. Code is available on &lt;a href="https://github.com/lbolla/HSGrep"&gt;github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks a lot for &lt;a href="http://codereview.stackexchange.com/q/6318/8638"&gt;all your useful suggestions&lt;/a&gt;! As soon as possible, I'll post some benchmarking &lt;a href="https://lbolla-info.netlify.app/blog/hsgrep-benchmarking/"&gt;here&lt;/a&gt;. (EDIT: &lt;a href="https://lbolla-info.netlify.app/blog/hsgrep-benchmarking/"&gt;benchmarks now available!&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;After downloading the &lt;a href="https://github.com/lbolla/HSGrep"&gt;source code&lt;/a&gt;, build install and run it with:&lt;/p&gt;</description></item><item><title>Haskell and VIM</title><link>https://lbolla-info.netlify.app/blog/haskell-and-vim/</link><pubDate>Sat, 15 Oct 2011 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/haskell-and-vim/</guid><description>&lt;p&gt;I had to tinker quite a bit before finding a decent configuration for vim to edit Haskell files. Here are the packages and config files I use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://projects.haskell.org/haskellmode-vim/"&gt;Haskell mode&lt;/a&gt;: interaction with &lt;a href="http://www.haskell.org/haddock/"&gt;Haddock&lt;/a&gt;, compiler integration, and other general settings.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.vim.org/scripts/script.php?script_id=1968"&gt;Indentation&lt;/a&gt;: proper source code indentation.&lt;/li&gt;
&lt;li&gt;More configs to enforce &lt;a href="http://urchin.earth.li/~ian/style/haskell.html"&gt;good style&lt;/a&gt; (no tabs, tabstops, etc.):&lt;/li&gt;
&lt;/ul&gt;
&lt;script src="https://gist.github.com/1289349.js"&gt; &lt;/script&gt;
&lt;p&gt;You can also have them &lt;a href="./assets/haskell-vim-config.tar.gz"&gt;bundled all together&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>HTTP client in Haskell</title><link>https://lbolla-info.netlify.app/blog/http-client-in-haskell/</link><pubDate>Mon, 26 Sep 2011 00:00:00 +0000</pubDate><guid>https://lbolla-info.netlify.app/blog/http-client-in-haskell/</guid><description>&lt;p&gt;To try to make sense of &lt;a href="http://learnyouahaskell.com/functors-applicative-functors-and-monoids"&gt;this&lt;/a&gt;, I decided to write a &amp;quot;simple&amp;quot; http client in Haskell in as many styles as I could think of:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-haskell" data-lang="haskell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;import&lt;/span&gt; Network.HTTP
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;import&lt;/span&gt; Control.Applicative
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;url&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;http://www.haskell.org/haskellwiki/Haskell&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-- Imperative style&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fetch_1&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; rsp &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;Network&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;HTTP&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;simpleHTTP (getRequest url)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; body &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; getResponseBody rsp
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; return (take &lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt; body)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-- With Functors&amp;#39; fmap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fetch_2&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; rsp &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;Network&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;HTTP&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;simpleHTTP (getRequest url)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; fmap (take &lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;) (getResponseBody rsp)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-- With Applicative&amp;#39;s &amp;gt;&amp;gt;=&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fetch_3&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fmap (take &lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;) (&lt;span style="color:#66d9ef"&gt;Network&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;HTTP&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;simpleHTTP (getRequest url) &lt;span style="color:#f92672"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; getResponseBody)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-- &amp;#34;fmap f x&amp;#34; is the same as &amp;#34;pure f &amp;lt;*&amp;gt; x&amp;#34; (Applicative&amp;#39;s law)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fetch_4&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pure (take &lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;) &lt;span style="color:#f92672"&gt;&amp;lt;*&amp;gt;&lt;/span&gt; (&lt;span style="color:#66d9ef"&gt;Network&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;HTTP&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;simpleHTTP (getRequest url) &lt;span style="color:#f92672"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; getResponseBody)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-- &amp;#34;pure f &amp;lt;*&amp;gt; x&amp;#34; is the same as &amp;#34;f &amp;lt;$&amp;gt; x&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;fetch_5&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; (take &lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;) &lt;span style="color:#f92672"&gt;&amp;lt;$&amp;gt;&lt;/span&gt; (&lt;span style="color:#66d9ef"&gt;Network&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;HTTP&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;simpleHTTP (getRequest url) &lt;span style="color:#f92672"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; getResponseBody)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It's a long time since I found so many new concepts while studying a new programming language&amp;hellip;&lt;/p&gt;</description></item></channel></rss>