Haskell, Vectors and Simple Mechanics – part 1.

I like vectors! A long time ago my maths teacher introduced me to them and I just like the way three numbers (typically three) can express the notion of a position in space and combining these under different operations can produce other interesting properties. Just recently I found this paper Learn Physics by Programming in Haskell which gives a very interesting Haskell oriented discussion on vectors and their use in mechanical problems. Reading it has inspired me to create my own implementation of vectors, bore you all senseless with it and see where it goes. What I’d like to do Read More

Text Classification 1.

What we’re trying to do is classify a piece of text, a review – it could be a review of film, a holiday, a car… anything. And we’ll claim that a review can either be positive e.g. ‘The bicycle was excellent and went very quickly uphill‘ . Or a review can be negative. e.g. ‘I was unhappy with the screwdriver, it was really poor and always turned the wrong way‘. The task is to take an arbitrary piece of text – a review – and decide which class it falls into – positive or negative. There are a number of Read More

Haskell Parsers Part 3.

This is the third part of parsing in Haskell. The previous posts are available at Haskell Parsers Part 1 and Haskell Parsers Part 2. In part one we defined a parser as a type and derived a very simple parser, a parser of char. Part two extended the ideas and created monadic, functorial and applicative instances of the parser type. This allowed us to combine parsers monadically – using ‘do’ or in an applicative style – e.g. using ‘<*>’ etc. Which to use is often a stylistic choice. In this post we’ll look at creating a few extra functions to Read More

Java Dockerfile.

Docker – what’s not to like?
Here’s a docker file that installs Java 8 over an Ubuntu base.
It also installs Git and Maven. It takes a little while to build but does provide a full JDK with git and maven.

To help remove unwanted images and stop any and all running containers here are two bash scripts.

Execution Statistics.

Recently I needed to find a way of logging the execution statistics of a number of methods in Java classes. The execution statistics included such things as number of invocations per unit of time, the longest and shortest execution time, the accumulated execution time per method etc. This needed to be done in a non-intrusive way – i.e. no direct modification of the code under examination. This type of orthogonal processing what AspectJ is designed for. A way to use AspectJ for this is now described. The steps are Setup Maven pom.xml with the required dependencies and the AspectJ build Read More

Haskell Parsers Part 2.

This post continues from Haskell Parsers Part 1 and here we look at elevating the parser first to a Functor then an Applicative and finally to a Monad. Creating Functor, Applicative and Monad instances for the parser will provide useful operations and allow parsers to be combined in interesting and useful ways. For a Functor we need to implement the fmap function and in the context of a Parser the signature of fmap is

in other words “A function a -> b applied to the result of a parser of ‘a’ gives a parser of ‘b’” and the implementation Read More

Simple Fractals in Haskell.

This posting was inspired by the ideas in ‘Composing Fractals’ by Mark P Jones. Fractals are generated by applying a function to the result of applying that function to the result of applying that function… Haskell has a very simple way of expressing this iterative function application:

i.e. iterate takes a function, that takes an ‘a’ and produces an ‘a’, along with an initial ‘a’ – the seed value. The function is then repeatedly applied ‘forever’ giving an infinite list of [a].

Of course we can’t really use all of an infinite list so we apply Haskell’s ‘take’ Read More

The expressiveness of Haskell – Trees.

A simple recursive data declaration is enough to define a tree.

This simply states that a Tree of ‘a’s is either Empty or (‘|’) it has a Node that has an ‘a’ and two other trees, a left subtree and a right subtree. The code to add an item to a tree is equally simple and recursive.

The function signature

states that ‘add’ takes a Tree of ‘a’, a value to add and returns a Tree of ‘a’. The only restriction on ‘a’ being that it must be of type ‘Ord’ meaning two ‘a’s can be compared Read More

Configuring an Embedded Tomcat Instance.

An ongoing project I’m working on involves setting up SAML based Single Sign On (SSO). At the core of this task is a legacy REST system that uses Netty and has its own http request dispatch system along with a tightly coupled persistence framework. Essentially the system does not have an application server that could have been used to process SAML’s Web Browser profile – a widely used means of obtaining authorisation from a SAML Identity Provider (IdP). I decided to investigate running Tomcat in embedded mode and so be able to use it for handling SAML messages. So this Read More

Haskell Parsers Part 1.

I really enjoy using Haskell. It’s probably the most intellectually satisfying programming language ever! Parsing is one of its many strengths and these next few posts will be about creating simple parsers from first principles and expressing them in two different ways. For parsing, start with a newtype definition for a Parser and a data constructor P that has a function String -> [(a, String)] which will parse the string for an ‘a’. The result of the parse is a list of tuples. The first element of a tuple being an ‘a’ and the other is whatever is left of Read More

ˆ Back To Top