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’ function to obtain however many items from the list.
For example in ghci:

Two of the most well known fractals are the Mandelbrot set and the Julia set and both are generated in similar but subtly different ways. With the Mandelbrot set the sequence is calculated with a seed of 0 and for the Julia set the seed is the current point from the (x, y) grid being considered. In either case the values in the sequence could become larger and larger but if they don’t then they are counted as ‘being in the set’.
These ideas about sequences converging, seeds etc are explained in a very accessible way at
So let’s see some code!

I think the code is fairly self explanatory and quite succinct given what it does.
The images below have been generated by the above code and they are the Mandelbrot and the four Julia images corresponding to ‘fixC1’ to ‘fixC4’. (The background colour has been manually changed to contrast with the page background).

Julia 1
Julia 2
Julia 3
Julia 4


Leave a Reply

Your email address will not be published. Required fields are marked *

ˆ Back To Top