Archive for the 'haskell' Category
Monday, April 13th, 2009
Let’s say that you really, really want some notion of objected oriented programming. So let’s make a class that represents a name, and some simple method calls on it: [code lang="haskell"] data S = S { name :: String } deriving (Show) firstname s = (words (name s))!!0 lastname s = (words (name s))!!1 [/code] [...]
Posted in coding, haskell | 1 Comment »
Friday, April 10th, 2009
A small snippet of code that demonstrates calling into a WordPress XML-RPC server with Haskell and HaxR. [code lang="haskell"] import qualified Data.Map as Map import Data.Maybe import Network.XmlRpc.Client import Network.XmlRpc.Internals server = "http://yourserver.wordpress.com/xmlrpc.php" -- extract multiple posts from the XML response extract :: Value -> [Map String Value] extract xmlresp = let ValueArray rs = [...]
Posted in coding, haskell | No Comments »
Sunday, March 29th, 2009
Ran into another interesting performance problem while converting a small test program over to Haskell. Let’s say that you want to walk through every line of a text file, collate character frequencies, and return anything that maps to a particular frequency. For purposes of explanation we’ll do something really silly like look for lines with [...]
Posted in coding, haskell | 4 Comments »
Saturday, March 28th, 2009
I was trying to track down some issues with some text processing programs that I was writing in Haskell, and ran into an interesting problem. I made one small change and my program ended up being 5 times slower, and I had to backtrack to try and find out what it was. So, given a [...]
Posted in coding, haskell | 1 Comment »
Thursday, March 19th, 2009
For comparison purposes, I was rewriting the silly little e-mail digest program in Haskell, using Python libraries for the IMAP interface (it’s available on Github). It’s hard to beat Python’s amazing collection of libraries. Cabal / hackage isn’t bad, but it doesn’t yet approach Python’s “batteries included” philosophy and ease of use. Anyway, I couldn’t [...]
Posted in coding, haskell, python | No Comments »
Wednesday, February 25th, 2009
I will be updating this as I go… but see also the Wikipedia page on string functions in various languages. Joining a string list [code lang='haskell'] -- Python: ",".join(lst) -- either... import Data.List intercalate "," lst -- or... import Data.List concat (intersperse "," lst) [/code] Splitting on a string [code lang='haskell'] -- a.split(ss) -- You [...]
Posted in coding, haskell | No Comments »
Tuesday, February 24th, 2009
I would like Haskell better if it didn’t do its best to make me feel stupid. Tasks that are easy in other languages, such, say, maintaining some state or generating a random number, become difficult. After banging my head on the State monad I finally arrived at a kind of understanding, which I put here [...]
Posted in coding, haskell | 2 Comments »