Posts tagged: HASKELL

Managing a Django project using darcs

Preamble

This article is two things:

  1. A description of one way to use version control with a Django project
  2. An introduction to using the darcs distributed version control system in particular

First, though, a mini-sermon which someday will be a post in the You Really Should series: You really should use version control. Most of you probably do. But if you’re among those not using version control to manage your software projects, start now! Learn a good version control system and start using it on just one project. You’ll work so much more productively and confidently that you’ll want to use version control everywhere. If you’re just getting started, learn Subversion – it is more or less the standard at this point, and employers and other programmers will assume you know it.

Neat Python hack: infix operators

I came across this neat Python hack on reddit today, a technique for defining arbitrary infix operators. Not overriding + or >> et al., but creating keyword-style pseudo-operators that… well, the code is probably as clear as any description I could come up with:

class infix(object):
    """
    Clever hack (slightly modified) for defining infix operators. 
    Via http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
    Intended for use as a decorator.
    
    >>> @infix
    ... def removing(str, chars):
    ...     for char in chars:
    ...         str = str.replace(char, '')
    ...     return str
    ...
    >>> print 'Hello, world!' |removing| 'eo'
    Hll, wrld!
    """
    def __init__(self, function):
        self.function = function
    def __ror__(self, other):
        return infix(lambda x: self.function(other, x))
    def __or__(self, other):
        return self.function(other)
    def __call__(self, value1, value2):
        return self.function(value1, value2)

Some people hate this kind of stuff. That’s why we call it a hack, to indicate that we don’t think it’s a great building block for your missile control software. Some of Those People still get their underoos in a bunch regardless. But you have to admit it’s damned clever.

Yegge's crusade

I’m generally a big fan of Steve Yegge’s rants. See this earlier post for links and quotes from some of my favorites. His writings were a significant influence in my decision to seriously look for a new language to learn in 2007 – I even bought Programming Language Pragmatics on his recommendation, piecemeal reading of which has definitely expanded my thinking (as well as dredging up parts of that Compiler Construction course I took back in 1989…).

Learning Haskell inch by inch

I did some more Haskell reading over the long weekend, mostly from Yet Another Haskell Tutorial*. There is definitely some challenging stuff (the Monads chapter in A Gentle Introduction to Haskell begins, ‘This section is perhaps less “gentle” than the others…’).

Overall, though, the combination of elegance and power and consistency in Haskell is very satisfying. The language has very little to apologize for.

I’m not really able to write much code yet, but I’ve started to be able to read it. I’m playing with adding Haskell coloring to dpaste, via the HsColour colorizing engine (written in Haskell, naturally). In trying to track down some formatting glitches – which may well turn out to be in my code, not theirs – I was actually able to look at the HsColour source and kind of understand how it does its thing.

The whitespace brigade

Syntactically significant whitespace is one of those debating points frequently raised in unproductive language thrashes involving Python. One persistent implication made by SSW-haters is that it’s a freakish mutation unique to Python. Or, if they’re feeling particularly vicious, they’ll bring up Fortran. Cold comfort.

In fact, there are quite a few other languages that have gone down this path. Flipping through a big fat book that I bought because Steve Yegge recommended it, I came across mention of a couple that were new to me. Then I went digging for more. Here’s an incomplete list: