Posts tagged: HASKELL

The Language I Will Kind of Learn in 2008: Smalltalk

In 2007, I took a whack at learning Haskell as my Language of the Year. It was an educational experience on more levels than I had expected. I didn’t get as far with the language as I might have hoped, but I did have the essential mind-opening experience of dealing with a purely functional, “lazy” language. My approach and style in my primary day-to-day language (Python) changed in a positive way. I really like Haskell and hope to continue playing, and possibly working, with it in the future.

Understanding tuples vs. lists in Python

Python has two seemingly similar sequence types, tuples and lists.

The difference between the two that people notice right away, besides literal syntax (parentheses vs. square brackets), is that tuples are immutable and lists are mutable. Unfortunately, because this distinction is strictly enforced by the Python runtime, some other more interesting differences in application tend to get overshadowed.

One common summary of these more interesting, if subtle, differences is that tuples are heterogeneous and lists are homogeneous. In other words:

OSCON 2007, Day 3

Today’s notes will be a bit more free-form. Now that the tutorial days are over and the main conference has begun, there are more sessions – and less time to write!

Keynotes

Tim O’Reilly raised the question of openness beyond source code. This felt a bit amorphous, but he did have a good point that when software is a service, availability of source code is not the whole story – if Google gave you their source, you couldn’t do anything with it. I can’t decide whether this is a real insight or a “duh”.

Real-World Haskell: A new book

This is exciting – three notable personalities from the Haskell world (Bryan O’Sullivan, Don Stewart, and John Goerzen) have teamed up to write a new book on Haskell for O’Reilly. Even better, it will be published under a Creative Commons license and released chapter-by-chapter on their website.

For now all that’s on their new site is a blog, but that’s sure to change over the coming days and weeks.

http://www.realworldhaskell.org/

I suspect this will become the standard intro to Haskell for working programmers like myself. If only it had been available at the beginning of my year-of-trying-to-learn-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.