Refactoring in Haskell: Adding an Argument

code,tips 10 December 2008 | 0 Comments

Just a small tip on this: When you add an argument to a function that already exists you should check the existing usage of the function. Say you have this: f x y z = … … and you want: f x y z w = … First of all you should check the contexts [...]

Tagged in , , , , , ,

Generating x86 assembly with Haskell

code 4 November 2008 | 3 Comments

A quick and dirty example: data Exp = Lit Int — literal value | Call String Exp — calling a function | Bin BinOp Exp Exp — binary operations | Param — the parameter deriving (Show,Eq)   data Function = Func String Exp — a function has a name and expression data BinOp = Add [...]

Tagged in , , ,

Simple socket programming with Haskell

code,university 15 October 2008 | 3 Comments

Here is a simple program showing socket programming with Haskell, created for a University assignment. It allows half-duplex (one way at a time) communication between two (or fewer ) computers: import Network import Data.Char (toLower) import Text.Regex.Posix ((=~)) import System.IO (hGetLine,hClose,hPutStrLn,hSetBuffering,BufferMode(..),Handle,stdout)   port = 8001 — a nice port number   main = withSocketsDo $ [...]

Tagged in , , ,

Sorted sums of a sorted list

code 25 September 2008 | 3 Comments

This is a post in response to this question over at the newly-spawned StackOverflow. Essentially: If we have a sorted list of numbers, how can we efficiently get a sorted list of the sums of every pair of numbers in that list? My initial reply is also there. I decided that, since I have a [...]

Tagged in , ,