1 July 2007 - An Haskell Web Store
Braintree Hemp is s web store completely written in Haskell.
Source code is available from:
darcs get http://braintreehemp.com.au/www.braintreehemp.com.au-WASH/
Here some of the features of the site.
- Written in Haskell, using WASH
- Shopping basket and checkout
- Google Maps
- Google Analytics
- Google Webmaster tools
- Template Haskell for HaskellDB description (describe a table or a field in one line)
- GPL, execpt where stated otherwise.
- Heavyweight Content Management System (CMS)
- Froogle RSS generator
- Configurable help for each page
- Concept of inventory levels
- Concept of users and permissions
- Naive-user management of products, users, and page content
- XML import tool and wizard for inventory level reconciliation
between warehouse and site database
All of these with 4200 lines of Haskell code. See the announcement for more details.
Comments (0) -
Leave a Comment
20 April 2007 - sgte parser rewrite
After some testing and the first experiences using sgte I'm doing a complete rewrite of the parser.
The code in the first version after some changes was quickly becoming unmantainable, so I decided to rewrite it from scratch.
The interface and the language is mainly the same as the previous version. There are a couple of new features and some smaller incompatible changes I will document before merging the new version in the main trunk.
The rewrite can be found in the TRY-parser-rewrite branch on the project page on Google.
You can checkout the branch with the command:
svn checkout http://sgte.googlecode.com/svn/branches/TRY-parser-rewrite sgte
The rewrite is almost finished. I have to fix some bugs in the if templates, and write documentation for the new features.
The new version should be available in the next week.
Comments (0) -
Leave a Comment
8 January 2007 - Haskell, bondage-and-discipline and separation-of-concerns programming
"This is a long, involved defense of purity, both in terms of what it affords us
in terms of power and in how it enforces "good" programming practices."
Read the complete article on Data.Syntaxfree
Comments (0) -
Leave a Comment
7 December 2006 - ''No Silver Bullet'' and Functional Programming
''No Silver Bullet'' and Functional ProgrammingInteresting blog article.
Comments (0) -
Leave a Comment
22 June 2006 - Functional Programming For The Rest of Us | defmacro.org
"If you're looking at the right
places you'll find at least one of these [challenging article] every couple of days. These articles are hard to get through and take
some time, so they start piling up. Before you know it, you have a list of links and a folder full of PDF files
and you wish you had a year in a small hut in the middle of the forest with nobody around for miles so you could
catch up."
This is one of these challenging articles. At least for those who are new to functional programming
Comments (0) -
Leave a Comment
10 May 2006 - Scheme Implementation in Javascript
A
scheme implementation written in javascript.
Read the article in the Bluish Coder blog.
Comments (0) -
Leave a Comment
8 May 2006 - Memoize utility
Here is a small utility I use to memoize expensive function calls in python. This utility too (like compose seen some days ago) is a traslation from lisp to python of a utility found in the book On Lisp by Paul Graham:
def memoize(fun):
cache = {}
def inner(*args, **kwargs):
cached = cache.get((args, repr(kwargs)), None)
if cached is None:
val = fun(*args, **kwargs)
cache[(args, repr(kwargs))] = val
return val
return cached
return inner
The memoize function uses an internal dict (cache) to store the values already calculated and returns a function containing a binding to the cache, hence a closures.
The closure when called first tries to search in the cache for a previously stored value corresponding to the arguments passed. If found the cached value is returned, otherwise the value is calculated and stored in the cache using the arguments and the repr() of the keyword arguments as the cache key. The repr is used because a dictionary, in python, is not hashable and so it can't be used as a key.
To test the utility we define a function that calculates the fibonacci sequence:
def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)
To use the memoize utility first we get the closure that memoizes the fib function:
import memoize
memo = memoize.memoize(fib)
Now we call the memo closure two times with the same argument and we time its execution:
def test_memoize_fib():
memo = memoize.memoize(fib)
start = time.time()
print memo(30)
end = time.time()
print "First call: %f" % (end - start)
start = time.time()
print memo(30)
end = time.time()
print "Second call: %f" % (end - start)
Calling the test function we get an output like this:
1346269
First call: 1.976743
1346269
Second call: 0.000072
Comments (0) -
Leave a Comment
1 May 2006 - Compose functions
Recently I'm reading the book "on Lisp" by Paul Garham. One the best books of programming I've ever read.
Here is an utility I translated from lisp to python to learn more on the use of closures. I wrote the function as part of a module functional (file
functional.py)
def compose(*fns):
if fns:
f1 = fns[-1]
fns = list(fns[:-1])
fns.reverse()
def inner(*args, **kwargs):
curr_arg = f1(*args, **kwargs)
for f in fns:
curr_arg = f(curr_arg)
return curr_arg
return inner
return None
The utility let you compose an arbitrary number of functions and apply each function to the result of the previous call. The first function can take any number of arguments or keyword arguments. All the others must take a single argument which is the result of the previous function call. Calling compose returns a closure that can be called with the number of arguments required by the first composed function:
>>> import functional
>>> import operator
>>> myop1 = functional.compose(operator.neg, operator.add)
>>> myop2 = functional.compose(operator.neg, operator.mul)
Now we can call the new operators like this:
>>> myop1(3, 2)
>>> myop1(3, 4)
>>> myop2(3, 2)
>>> myop2(3, 4)
and we get respectively:
-5, -7, -6 and -12
First operator.add (or operator.mul) is called with the two arguments passed. Then operator.neg is called with the result of the previous call as an argument.
Comments (0) -
Leave a Comment
21 February 2006 - Javascript Closures
A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).
An easier way to define closures is using the words of Paul Graham in On Lisp: "Closures are functions with local state".
Let's see a classical example:
function adder(n) {
function inner(x) {
return x+n;
}
return inner
}
Function adder takes an argument and returns a closure where the variable n is bound at the time the function is defined. So we can call adder many times and get different closures whose behaviour depends on the binding of n:
var adder2 = adder(2);
var adder10 = adder(10);
alert(adder2(5)); //alerts 7
alert(adder10(5)); //alerts 15
Closure are a powerfull and elegant tool in a programmer's toolbox. I find myself using them for a lot of different things from defining callback functions, to easy refactoring of code, define control structures, to customize function behavior by passing closures as arguments.
For me they are invaluable, so I'll be back on them soon.
Comments (0) -
Leave a Comment
21 September 2005 - Lambda the Ultimate
Lambda the Ultimate deals with issues directly related to programming languages, and programming language research.
Comments (0) -
Leave a Comment
29 July 2005 - Erlang
Recently I step into erlang. It' s a really interesting language,
specially if you are into concurrent, distributed, fault tolerant,
applications. Take a look at
this tutorial and then you can continue with this pdf:
Making reliable distributed systems in the presence of software errors.
Comments (0) -
Leave a Comment
14 January 2005 - Use continuations to develop complex Web applications
A programming paradigm to simplify MVC for the Web.A continuation is traditionally defined as a function representing "the rest of the computation" or "what to do next." In other words, sending the intermediate result (generated by the preceding computation) to a continuation should yield the final result of the overall computation.
Read more.
Comments (0) -
Leave a Comment
14 January 2005 - Better programming through effective list handling
Techniques for using linked lists in C and -- smarter still -- Scheme.
A Scheme introduction starting from a linked lists imlementation in C.
Comments (0) -
Leave a Comment