Skip to content

Haskell and VIM

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:

  • Haskell mode: interaction with Haddock, compiler integration, and other general settings.
  • Indentation: proper source code indentation.
  • More configs to enforce good style (no tabs, tabstops, etc.): 
    " Add to .vimrc
    " Need to have .vim/compiler/ghc.vim

    augroup HSK
            au Bufenter *.hs compiler ghc
            autocmd FileType haskell setlocal formatoptions+=t
            autocmd FileType haskell let b:ghc_staticoptions = '-Wall -Werror'
    augroup END

    " Add to .vim/ftplugin/haskell.vim

    " From Good Haskell Style http://urchin.earth.li/~ian/style/haskell.html
    setlocal expandtab
    setlocal tabstop=8
    setlocal shiftwidth=8
    setlocal textwidth=79
    " Add to .vim/syntax/haskell.vim

    " From Good Haskell Style http://urchin.earth.li/~ian/style/haskell.html

    syn cluster hsRegions add=hsImport,hsLineComment,hsBlockComment,hsPragma
    syn cluster hsRegions add=cPreCondit,cCppOut,cCppOut2,cCppSkip
    syn cluster hsRegions add=cIncluded,cDefine,cPreProc,cComment,cCppString

    syn match tab display "\t" containedin=@hsRegions
    hi link tab Error
    syn match trailingWhite display "[[:space:]]\+$" containedin=@hsRegions
    hi link trailingWhite Error

You can also have them bundled all together.

Tagged , ,

they broke delicious

the new redesign of delicious.com broke so many things, that I thought I had to take notes:

  • bookmarklet in Chrome can’t be drag-n-dropped to the toolbar. its javascript code is also hard to copy and paste to create the bookmarklet “manually”.
  • install links for the chrome and firefox extensions redirect to empty pages.
  • documentation for developer is coming soon (!)
  • the top-right menu with the logged-in username and stuff is the most horrible I’ve ever seen: it changes its width on hover, the corners look interrupted (in Chrome, at least — I’m not bothered trying with other browsers)
  • what the hell are stacks? grouping can be done with tags, already, and I don’t want that much space in the page taken by a “social” feature! who needs it?
  • the list of links in the main personal page only shows 8 links on my screen… 8 links?! there’s way too much padding, too whitespaces, too much to scroll… it’s a bookmarking services, it should show you bookmarks in the most friendly way!
  • image: why should I use an image for myself? and if I don’t use one, I got assigned one by default… please…

I’ll add more to the list in the future.

Tagged

http client in haskell

To try to make sense of this, I decided to write a “simple” http client in Haskell in as many styles as I could think of:

import Network.HTTP
import Control.Applicative

url = "http://www.haskell.org/haskellwiki/Haskell"

--  Imperative style
fetch_1 = do
	rsp <- Network.HTTP.simpleHTTP (getRequest url)
	body <- getResponseBody rsp
	return (take 1000 body)

--  With Functors' fmap
fetch_2 = do
	rsp <- Network.HTTP.simpleHTTP (getRequest url)
	fmap (take 1000) (getResponseBody rsp)

--  With Applicative's >>=
fetch_3 = fmap (take 1000) (Network.HTTP.simpleHTTP (getRequest url) >>= getResponseBody)

--  "fmap f x" is the same as "pure f <*> x" (Applicative's law)
fetch_4 = pure (take 1000) <*> (Network.HTTP.simpleHTTP (getRequest url) >>= getResponseBody)

--  "pure f <*> x" is the same as "f <$> x"
fetch_5 = (take 1000) <$> (Network.HTTP.simpleHTTP (getRequest url) >>= getResponseBody)

it’s a long time since I found so many new concepts while studying a new programming language…

Tagged , , ,

pylint.vim

vim + python + pylint is a powerful combination, especially when using this vim plugin.

unfortunately, the script stopped working after a pylint upgrade:

$ pylint --version
pylint 0.24.0,
astng 0.22.0, common 0.56.0
Python 2.7.2 (default, Jun 29 2011, 11:10:00)
[GCC 4.6.1]

you can download the fixed version here!

if interested, the patch looks like this:

diff pylint.vim.orig pylint.vim
69c69
< CompilerSet makeprg=(echo\ '[%]';\ pylint\ -r\ y\ %)
---
> CompilerSet makeprg=(echo\ '[%]';\ pylint\ -r\ y\ --output-format=parseable\ %)
74c74
< CompilerSet efm=%+P[%f],%t:\ %#%l:%m,%Z,%+IYour\ code%m,%Z,%-G%.%#
---
> CompilerSet efm=%f:%l:\ [%t]%m,%f:%l:%m
Tagged , ,

md5 vs sha1 in python

If you are interested to know if the myth about MD5 being faster than SHA1 holds for Python, here is the result I got on my box:

In [1]: import hashlib

In [2]: %timeit hashlib.md5('text text text').hexdigest()
1000000 loops, best of 3: 1.29 us per loop

In [3]: %timeit hashlib.sha1('text text text').hexdigest()
1000000 loops, best of 3: 1.4 us per loop

Result is: MD5 is faster, but only just, in Python 2.7.2. Considering that MD5 is broken, I think I’ll use SHA1…

Tagged , , , ,

sleepsort

to honor the funniest thread in months, here is a lisp implementation of sleepsort!

(use-package :sb-thread)

(defun show (item)
  (sleep item)
  (format t "~S~%" item))

(defun sleep-sort (lst)
  (mapcar
    #'(lambda (item) (make-thread #'(lambda () (show item))))
    lst))
Tagged ,

Scappatella con Ryanair

Dal sito Ryanair.

javascript templating benchmark

there are many popular libraries to do templating in javascript.

the most popular are:

I decided to benchmark them, so I created a simple “hello world” test. you can find it here.

as usual, the results are interesting. here are, on my box:

Firefox 3.6 Chrome 11.0 Safari 5.0
JQuery Template 297ms 138ms 113ms
Pure 309ms 43ms 36ms
Resig 309ms 41ms 41ms
Trimpath 15ms 5ms 6ms
JQote2 7ms 1ms 6ms

a part from the obvious result that Firefox is the slowest browser of all, I’m astonished by the excellent performance of JQote2!

time to go home!

10/10

better go before I break it…

case sensitive Google search

Case Sensitive Google Search

Case Sensitive Google Search in action

Google does not support “case sensitive” searches (and here and here).

it does seem to return slightly different results depending on the case of the search query, but if you are only interested in the exact “case sensitive” matches you’re on your own.

to solve this problem, I’ve written a small JS snippet that shades results from Google searches if not exactly matching the case-sensitive search query.

you can download it as:

let me know what you think!

Tagged , , , , , ,