Strangelights

Another tech blog.

 

Foundations of F#

Published: 2006-10-08

Wow. Just seen that my book has been officially announced on my publisher’s, Apress, website. You can see the announcement for yourselves here. It is also available for pre-order on amazon.com.

Continue reading ...

I was playing around with implementing drawing a Mandelbrot set in F#. F# makes this very easy because of its Microsoft.FSharp.Math namespace provides a very easy to use complex implementation which means you just need to type out the equation and viola you have the Mandelbrot set. Or so I thought. My implementation end up being about 40 lines about 11 of which were the equation on which the Mandelbrot set was based and the rest of the code was infrastructure to use the equation and display the results. While the resulting code, shown below, is still reasonably short this isn’t what I was hopping for.

 

open System
open System.Drawing
open System.Windows.Forms
open Microsoft.FSharp.Math

let c_max = Complex.one + Complex.onei
let c_min = Complex.mkRect(-1.0, -1.0)
let iterantions = 18.0

let is_in_mandelbrot_set x y =
    let c = ref (Complex.mkRect(x,y)) in
    let count = ref 0.0 in
    let const_c = !c in
    while (c_max > !c) && (!c > c_min) && (!count < iterantions) do
        c := (!c * !c) + const_c;
        count := !count + 1.0
    done;
    !count

let intergral = 1.0 / 200.0
let offset = -1.0

let get_coord (x, y) =
     let fx = ((float_of_int x) * intergral) + offset in
     let fy = ((float_of_int y) * intergral) + offset in
     fx, fy
        
let form =
    let image = new Bitmap(400, 400) in
    for x = 1 to 399 do
        for y = 1 to 399 do
            let fx, fy = get_coord (x, y) in
            let no = is_in_mandelbrot_set fx fy in
            if no = iterantions then
                image.SetPixel(x,y, Color.Black)
        done
    done;
    let temp = new Form() in
    temp.Paint.Add(fun e -> e.Graphics.DrawImage(image, 0, 0));
    temp   

[]   
do Application.Run(form)
 

Continue reading ...

Although already spotted by optionsScalper here, I thought I’d mention this myself. Frank Antonsen a programmer from Copenhagen (one of my favorite cities) has written two articles which are available freely on ASP Today until 15th July. So hurry you still have time to read them freely.

 

The first article is a general introduction to F# and then the second digs a little deep into F# data types. Both are well written but I enjoyed part two more.

Continue reading ...

I’ve been playing with F# and Windows Presentation Foundation (WPF a.k.a Avalon) and the combination is really nice. WPF comes with a new(ish) markup language called Xaml. This is another declarative language that works in a complimentary way to F#. Xaml allows you initialise an object graph into a specific state in a declarative style; moreover various designers will soon be come available to do this, so you won’t even have to hand code the Xaml file. You can then load the xaml file and use F# to tweak resulting images.

 

I have written a sample in which we create a 3D scene with one object, a photo, which rotates slowly though 180 degrees. The vast majority of this is written in Xaml, the only thing we do in F# is add the plane to scene and apply various effects to it.

Continue reading ...

F# does not get support C# style continuations yet; I am reliably informed that it will do at some point.

 

However if you can not wait that long it is already fair easy to get C# style continuations by implementing System.Collections.Generic.IEmunerable your self. What’s more this can be implemented as a library function then implementing your enumerator becomes just a couple of lines of code.

Continue reading ...

 

Alois Kraus on F#

Published: 2006-05-29

Alois Kraus just made this nice post about functional programming in F# and C#. I enjoyed the article very much and he even bigs up one of my own posts, which of course tickled me.

 

However, I disagree with quite a lot of what he said in his conclusion paragraph. He writes:

Continue reading ...

It’s a lovely evening here in Brussels and I am sitting on my balcony, I think summer might have finally arrived, except every time I think that we get two days of clouds and rain. The only problem with this is below are two restaurants with out terraces who have plenty of customers, the only problem with this is the smell drifts up into my apartment makes me hungry.

 

Anyway I have been neglecting my blog lately, there is a reason for this, but nether the less I thought I should try and do something to correct this.

Continue reading ...

 

New F# hub

Published: 2006-04-27

It seems there is a new F# hug in town; I will of course be signing up, why don’t you too?

http://cs.hubfs.net

 

Continue reading ...

Last September I as I’d walk to the RER station to catch the train to La Défense, I could not help notice how amazing the colours of the sun rise where. So one morning I got up early to take some photos here are the results.

 

Continue reading ...

Recently Don Syme made a post to the F# mailing list about some proposed changes to the F# libraries. In it talked about the virtues of using the new |> operator, sighting the following example as something it would be difficult without it:

 

let methods = System.AppDomain.CurrentDomain.GetAssemblies()

Continue reading ...